Azzera filtri
Azzera filtri

Summing columns of table

214 visualizzazioni (ultimi 30 giorni)
Leonor Vieira Dias
Leonor Vieira Dias il 29 Gen 2021
Commentato: Mathieu NOE il 29 Gen 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

Risposta accettata

Mathieu NOE
Mathieu NOE il 29 Gen 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 Commenti
Leonor Vieira Dias
Leonor Vieira Dias il 29 Gen 2021
Briliant, it worked! Thank you
Mathieu NOE
Mathieu NOE il 29 Gen 2021
you're welcome !!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by