フィルターのクリア

Summing columns of table

214 ビュー (過去 30 日間)
Leonor Vieira Dias
Leonor Vieira Dias 2021 年 1 月 29 日
コメント済み: Mathieu NOE 2021 年 1 月 29 日
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)
  2 件のコメント
Leonor Vieira Dias
Leonor Vieira Dias 2021 年 1 月 29 日
Briliant, it worked! Thank you
Mathieu NOE
Mathieu NOE 2021 年 1 月 29 日
you're welcome !!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by