MATLAB Answers

BoIs
0

Calculate statistical parameters from certain rows of a matrix

Asked by BoIs
on 12 Aug 2019
Latest activity Commented on by BoIs
on 12 Aug 2019
I have data of days and temperature in specific intervals recorded through out that particular day: eg
Day Temp
1 24
1 24.5
1 24.5
2 25
2 25
2 25
3 25.5
3 25.5
3 25.5
and so on for many number of days through. If I want to take the mean of all the temperature values from only day 1, how would I go about doing this using indexing?

  0 Comments

Sign in to comment.

2 Answers

Answer by madhan ravi
on 12 Aug 2019
 Accepted Answer

Wanted=splitapply(@mean,x(:,2),findgroups(x(:,1))) % x(:,1) is Day and x(:,2) is Temperature
% or if you're using version prior to 2015b then:
Wanted=accumarray(Day,Temperature,[],@mean);
For only one day it’s simply:
day = 1;
mean(Temperature(Day==day))

  1 Comment

Works perfectly! Thank you

Sign in to comment.


Answer by Jos (10584)
on 12 Aug 2019

help grpstats
help accumarray

  0 Comments

Sign in to comment.