Summing columns of table

214 次查看(过去 30 天)
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

采纳的回答

Mathieu NOE
Mathieu NOE 2021-1-29
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)

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by