Retime for custom timestep (6 hour)

13 visualizzazioni (ultimi 30 giorni)
NOtway
NOtway il 31 Mag 2023
Commentato: NOtway il 31 Mag 2023
I have a timetable that I need to get the annual 6-hourly maximum values for. The data is currently in an hourly timestep and my approach has been:
%retime the data into 6 hour sums, beginning from the first timestep (so
%the sums of hours 1-6, 7-12, etc)
TT_6hr_1 = retime(TT, 'regular', 'sum', 'TimeStep', hours(6));
%find maximum value for each year
Aggregate_6hr_1_max = retime(Aggregate_6hr_1,"yearly", "max");
%delete the first hour of data, and then repeat process (theoretically
%should be sums of hours 2-7, 8-13 etc)
TT(1,:) = [];
TT_6hr_2 = retime(TT, 'regular', 'sum', 'TimeStep', hours(6));
TT_6hr_2_max = retime(TT_6hr_2,"yearly", "max");
%repeat 4 more times to cover all possible combinations of 6 hours
%then simply find the maximums from TT_6hr max 1 through 6 by synchronising and
%using a max function
However the retime does not start each 6 hour time period from the first timestep of the data - it sums it from 12am-6am, 6am-midday, etc. So each iteration gives the same result.
If there a way to specify for the retime function to take the first timestep starting at the first data point? or alternatively to push the hours in the timetable back or forward by an hour (ie move the time, rather than the data), the actual times arent really relevant since I'm only interested in an annual maximum, so doesn't matter if I move the times around.

Risposta accettata

Cris LaPierre
Cris LaPierre il 31 Mag 2023
When you use the automatic binning options of TimeTables, this is how the new times are created. If you want to ensure your new times start at a specific time, you need to specify the times using the following syntax
For your code, that might look like this.
newTime = TT.Time(1):hours(6):TT.Time(end);
TT_6hr_1 = retime(TT, newTime,'sum')

Più risposte (1)

Steven Lord
Steven Lord il 31 Mag 2023
You're using this syntax from the retime documentation page:
"TT2 = retime(TT1,'regular',method,'TimeStep',dt) calculates regularly spaced row times using the time step dt. The dt input argument is a scalar duration or calendar duration, specifying a time step of any size. The row times of TT2 span the range of row times of TT1."
But it sounds like you want this syntax instead:
"TT2 = retime(TT1,newTimes,method) adjusts the timetable variables data to the time vector newTimes, using the method specified by method. The newTimes time vector can be irregular, but it must be a sorted datetime or duration vector and contain unique values. The times in newTimes become the row times of TT2."
Use min or bounds on the time vector in TT1 and the colon operator to generate the vector for the newTimes input argument.

Categorie

Scopri di più su Timetables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by