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 visualización (últimos 30 días)
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

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 12 de Sept. de 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 comentarios
Mohammed Yousuf
Mohammed Yousuf el 12 de Sept. de 2019
datetime function is not available in my Matlab version .
I am using Matlab 2014a
Andrei Bobrov
Andrei Bobrov el 12 de Sept. de 2019
Editada: Andrei Bobrov el 12 de Sept. de 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));

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by