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 vue (au cours des 30 derniers jours)
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

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 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 commentaires
Mohammed Yousuf
Mohammed Yousuf le 12 Sep 2019
datetime function is not available in my Matlab version .
I am using Matlab 2014a
Andrei Bobrov
Andrei Bobrov le 12 Sep 2019
Modifié(e) : Andrei Bobrov le 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));

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by