Sum and Average of column in Matrix

2 views (last 30 days)
I have a 27 x 34 table, which has different column headings such as 'start freq, end freq, and Duration90s'.
I'm wanting to calculate the sum and then the average of only one column. That being 'Duration90s'
I've tried: sum('Duration90s')
meandur = sum('Duration90s)/27
*27 indicates the number of entries
I have changed the code a few times but I keep receiving the sum = 1058
and the mean dur = 39.1852
However the correct answer should be sum = 14
and the mean dur = 0.518519

Accepted Answer

madhan ravi
madhan ravi on 14 May 2019
Edited: madhan ravi on 14 May 2019
Wanted=T(:,'Duration90s');% here T is your table
% Google how to access data from table
sum(Wanted)
mean(Wanted)
  7 Comments
Rachael Courts
Rachael Courts on 14 May 2019
I actually got it to work by:
sum(Wanted.Duration90s)
mean(Wanted.Duration90s)
madhan ravi
madhan ravi on 14 May 2019
Ah, yes also:
Wanted=T{:,'Duration90s'}; % {} was missing

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!