James, you're right about retime, what you're looking for is a "seasonal average" (I forget the right term) where all 10:00's across all days are grouped together. There are several ways to do this, here's two of them:
Create some simple data:
>> X = randn(10,1);
>> day = [1 1 2 2 3 3 4 4 5 5]';
>> hour = [0 12 0 12 0 12 0 12 0 12]';
>> tt = timetable(X,'RowTimes',datetime(2017,1,day,hour,0,0))
tt =
10×1 timetable
Time X
____________________ _________
01-Jan-2017 00:00:00 0.083462
01-Jan-2017 12:00:00 0.42727
02-Jan-2017 00:00:00 1.3205
02-Jan-2017 12:00:00 0.72672
03-Jan-2017 00:00:00 1.0172
03-Jan-2017 12:00:00 0.0081844
04-Jan-2017 00:00:00 1.711
04-Jan-2017 12:00:00 0.17656
05-Jan-2017 00:00:00 1.5919
05-Jan-2017 12:00:00 0.47648
Add hour of day as a new variable, and compute grouped means by Hour:
>> tt.Hour = tt.Time.Hour;
>> varfun(@mean,tt,'GroupingVariable','Hour','OutputFormat','table')
ans =
2×3 table
Hour GroupCount mean_X
____ __________ ________
0 5 -0.20561
12 5 -0.6783
Or, add day as a new variable and unstack the data by hour within day:
>> tt.Day = tt.Time.Day;
>> ttu = unstack(tt,'X','Hour','GroupingVariable','Day');
>> ttu.Time.Format = 'defaultDate'
Warning: Variable names were modified to make them valid MATLAB identifiers.
ttu =
5×3 timetable
Time Day x0 x12
___________ ___ ________ _________
01-Jan-2017 1 0.66052 -0.071304
02-Jan-2017 2 -0.37509 0.44703
03-Jan-2017 3 1.085 -1.8861
04-Jan-2017 4 -1.7021 -2.0648
05-Jan-2017 5 -0.69644 0.1836
Then you can compute means by hour. I would think the first version is more useful unless you want the unstacked version for something else.
Best Answer