I have time series data of 1 year each day 2880 values row wise so a matrix of 365X2880. I want to do monthly average. January 31 days average one file of one month, so that I can finally get 12 files each of monthly average.

1 view (last 30 days)
I have time series data of 1 year each day 2880 values row wise so a matrix of 365X2880.
I want to do monthly average. January 31 days average one file of one month, so that I can finally get 12 files each of monthly average.
I think should be considered, days in each month are not same. I have 2015 data so it is not a leap year, Therefore february contain 28 days.
Plese help me to come out of it

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 12 Sep 2019
A - you're array 365 x 2880, in example per 2015 year.
t = (datetime(2015,1,1):datetime(2015,12,31))';
TT = array2timetable(A,'RowTimes',t);
T_out = retime(TT,'monthly','mean');
  2 Comments
Andrei Bobrov
Andrei Bobrov on 12 Sep 2019
Edited: Andrei Bobrov on 12 Sep 2019
Well then for old MATLAB:
t = (datenum(2015,1,1):datenum(2015,12,31))';
[y,m] = datevec(t);
[a,~,c] = unique([y,m],'rows');
[ii,jj] = ndgrid(c,1:size(A,2));
out = [a, accumarray([ii(:),jj(:)],A(:),[],@mean)];
or with tables:
t = (datenum(2015,1,1):datenum(2015,12,31))';
[y,m] = datevec(t);
T = array2table([y,m,A]);
T.Properties.VariableNames = [{'Year','Month'},sprintfc('Data%d',1:size(A,2))];
T_out = varfun(@mean,T,'GroupingVariables',{'Year','Month'},'InputVariables',T.Properties.VariableNames(3:end));

Sign in to comment.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!