Borrar filtros
Borrar filtros

Summing columns of table

214 visualizaciones (últimos 30 días)
Leonor Vieira Dias
Leonor Vieira Dias el 29 de En. de 2021
Comentada: Mathieu NOE el 29 de En. de 2021
Hello,
I have imported a table from excel to Matlab in it's correct form.
I have already summed the first two columns and added as new column to table by doing:
T = readtable("Table 1.xlsx")
T.Early = (T.x22_early) + (T.x7_early)
However, the rest of the table is very long. I was wondering if there is a simpler way than to enter all the columns individually as I did previously.
Thank you in advance

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 29 de En. de 2021
hello
see example for taking mean values :
Find the Average Across Each Row
Extract the data from the second, third, and fourth variables using curly braces, {}, find the average of each row, and store it in a new variable, TestAvg.
T.TestAvg = mean(T{:,2:end},2)
T=10×5 table
Gender Test1 Test2 Test3 TestAvg
__________ _____ _____ _____ _______
HOWARD {'male' } 90 87 93 90
WARD {'male' } 87 85 83 85
TORRES {'male' } 86 85 88 86.333
PETERSON {'female'} 75 80 72 75.667
GRAY {'female'} 89 86 87 87.333
RAMIREZ {'female'} 96 92 98 95.333
JAMES {'male' } 78 75 77 76.667
WATSON {'female'} 91 94 92 92.333
BROOKS {'female'} 86 83 85 84.667
KELLY {'male' } 79 76 82 79
now do it for sum , and specify column index if needed :
T.TestSum = sum(T{:,2:end},2)
  2 comentarios
Leonor Vieira Dias
Leonor Vieira Dias el 29 de En. de 2021
Briliant, it worked! Thank you
Mathieu NOE
Mathieu NOE el 29 de En. de 2021
you're welcome !!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by