monts in year sequence, string, matrix

조회 수: 5 (최근 30일)
Nikola Ostojic
Nikola Ostojic 2021년 1월 16일
댓글: Nikola Ostojic 2021년 1월 16일
I have a series of 365 days. I need to divide the elements of the array into months with 31, 28, 31, 30 .. days and add the values ​​for the months.
The result should be a series of 12 months with aggregated values ​​for each month.
can i have a reshape function?

채택된 답변

Walter Roberson
Walter Roberson 2021년 1월 16일
Convert to a timeseries() object and use retime()
Or:
Data = rand(365,1);
Data_timestamp = datetime(2021, 1, 1:365).'; %use non-leap year !
month_totals = accumarray(month(Data_timestamp), Data)
month_totals = 12×1
17.6917 12.5502 14.1349 17.2993 14.2127 17.4742 16.3479 14.0845 13.4153 15.4119

추가 답변 (1개)

dpb
dpb 2021년 1월 16일
Add the date to a timetable and retime with aggregation--
tt=timetable(datetime(yr,1,1:365).',data); % make timetable of days and your data
ttAgg=retime(tt,'monthly','sum');
  댓글 수: 1
Nikola Ostojic
Nikola Ostojic 2021년 1월 16일
Thanks for the reply!! :))
I believe it works, but i already got the reply.

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by