# Divide annual timeseries to monthly ones

23 views (last 30 days)
Ancalagon8 on 15 Jan 2023
Commented: Star Strider on 24 Jan 2023
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 on 15 Jan 2023
A for loop is the easiest way to do this —
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.
.
Star Strider on 24 Jan 2023
As always, my pleasure!

Christopher McCausland on 15 Jan 2023
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 CommentsShowHide 1 older comment
Christopher McCausland on 15 Jan 2023
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

### Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by