monts in year sequence, string, matrix
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
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)
更多回答(1 个)
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');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!