Divide annual timeseries to monthly ones

13 次查看(过去 30 天)
For a specific year I have created an hourly timetable using retime:
VarPerHour = retime(T, 'hourly', 'sum');
How can I divide VarPerHour into 12 monthly timetables?

采纳的回答

Star Strider
Star Strider 2023-1-15
A for loop is the easiest way to do this —
LD = load(websave('dataset','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1255052/dataset.mat'));
T = LD.TT1;
VarPerHour = retime(T, 'hourly', 'sum')
VarPerHour = 8760×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 588 01-Jan-19 01:00:00 608.11 01-Jan-19 02:00:00 608.25 01-Jan-19 03:00:00 608.33 01-Jan-19 04:00:00 608.25 01-Jan-19 05:00:00 608.4 01-Jan-19 06:00:00 608.59 01-Jan-19 07:00:00 608.9 01-Jan-19 08:00:00 609.32 01-Jan-19 09:00:00 599.51 01-Jan-19 10:00:00 609.61 01-Jan-19 11:00:00 609.51 01-Jan-19 12:00:00 609.39 01-Jan-19 13:00:00 609.44 01-Jan-19 14:00:00 609.58 01-Jan-19 15:00:00 609.83
for k = 1:12
MMidx = month(VarPerHour.date_time) == k;
VarPerHourMonth{k,:} = VarPerHour(MMidx,:);
end
VarPerHourMonth
VarPerHourMonth = 12×1 cell array
{744×1 timetable} {672×1 timetable} {744×1 timetable} {720×1 timetable} {744×1 timetable} {720×1 timetable} {744×1 timetable} {744×1 timetable} {720×1 timetable} {744×1 timetable} {720×1 timetable} {744×1 timetable}
VarPerHourMonth{1}(1:5,:)
ans = 5×1 timetable
date_time Temperature __________________ ___________ 01-Jan-19 00:00:00 588 01-Jan-19 01:00:00 608.11 01-Jan-19 02:00:00 608.25 01-Jan-19 03:00:00 608.33 01-Jan-19 04:00:00 608.25
VarPerHourMonth{12}(1:5,:)
ans = 5×1 timetable
date_time Temperature __________________ ___________ 01-Dec-19 00:00:00 590.64 01-Dec-19 01:00:00 193.5 01-Dec-19 02:00:00 0 01-Dec-19 03:00:00 0 01-Dec-19 04:00:00 0
This uses an existing timetable. It should work with the one you are currently using as well.
.
  15 个评论

请先登录,再进行评论。

更多回答(1 个)

Christopher McCausland
Hi Ancalogon,
Having a look at the documentation here; you can just replace hourly with any timestep such as:
Time Step
'yearly'
'quarterly'
'monthly'
'weekly'
'daily'
'hourly'
'minutely'
'secondly'
Have you tried;
VarPermonth = retime(T, 'monthly', 'sum');
Let me know if this is what you are looking for, if not please provide a snippit of the data and the expected output.
Christopher
  2 个评论
Ancalagon8
Ancalagon8 2023-1-15
Thanks for your answer @Christopher McCausland.
VarPermonth = retime(T, 'monthly', 'sum');
returns me only one value per month (12X1 timetable).
VarPerHour = retime(T, 'hourly', 'sum') is a 8760X1 timetable (365 days X 24 hours).
I need to split VarPerHour per month but keep all values.
Christopher McCausland
Hi Ancalagon,
I get what you want now.
What you really need to do is filter ValPerHour by months, heres an example of how to do so:
And also an ealier suggestion from Walter;
I hope this helps!
Christopher

请先登录,再进行评论。

类别

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