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 (최근 30일)
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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 9월 12일
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
Mohammed Yousuf
Mohammed Yousuf 2019년 9월 12일
datetime function is not available in my Matlab version .
I am using Matlab 2014a
Andrei Bobrov
Andrei Bobrov 2019년 9월 12일
편집: Andrei Bobrov 2019년 9월 12일
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));

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by