How to partition hourly Data by month

4 views (last 30 days)
Hi,i have 20-years hourly data converted into timetable,i need to retime my data to month running mean timetable and then substract my data from it. is it possible with retime function ? Otherwise, how to partition the data by month using reshape and taking into account leap and regular years ?
Thanks

Accepted Answer

Akira Agata
Akira Agata on 13 Mar 2018
Yes, you can calculate monthly mean of your timetable by retime function, like this. More details can be found in the help page of retime function .
outputTT = retime(yourTT,'monthly','mean')
  8 Comments
Akira Agata
Akira Agata on 20 Mar 2018
Regarding the second part of your question, please add the following:
% Calculate X(h,d,m,y)-X(h,m) and store as TT.Data2
TT.Data2 = TT.Data - Xresult.DataAvg(group);
locas
locas on 20 Mar 2018
This is genius Akira ! Thanks so much .

Sign in to comment.

More Answers (1)

Akira Agata
Akira Agata on 16 Apr 2018
When your data has multiple columns, the following will work.
% Sample hourly data from 1989/1/2 to 2004/12/31
Time = (datetime(1989,1,2,0,0,0):hours(1):datetime(2004,12,31,23,0,0))';
Data1 = rand(size(Time));
Data2 = rand(size(Time));
TT = timetable(Time,Data1,Data2);
% Calculate hourly data mean X(h,m)
[group,Hour,Month] = findgroups(hour(TT.Time),month(TT.Time));
DataAvg = splitapply(@mean,TT{:,:},group);
Xresult = [table(Hour,Month),array2table(DataAvg)];
Xresult.Properties.VariableNames(3:end) = TT.Properties.VariableNames;
% Calculate X(h,d,m,y)-X(h,m) for each column and store as TT2
TT2 = TT{:,:} - Xresult{group,3:end};
TT2 = array2table(TT2,'VariableNames',TT.Properties.VariableNames);
TT2 = timetable(Time,TT2);

Categories

Find more on Timetables 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!