timetable.retime
timetable: ttB = retime (ttA, newTimes)
timetable: ttB = retime (ttA, newTimeStep)
timetable: ttB = retime (…, method)
timetable: ttB = retime (…, Name, Value)
Resample a timetable onto new row times.
ttB = retime (ttA, newTimes) returns a
timetable whose rows sit at newTimes, a datetime or
duration vector of the same kind as the row times of
ttA, sorted and without repeats.
ttB = retime (ttA, newTimeStep) builds those
times instead from a time unit, one of 'secondly',
'minutely', 'hourly', 'daily',
'weekly', 'monthly', 'quarterly' and
'yearly'. The grid starts at the unit’s own boundary at or
before the first row time. A filling method reads the times as sample
points and runs the grid to the first boundary at or after the last row
time, so three hours of data retimed 'daily' spans two days; an
aggregating method reads them as bins and stops at the bin holding the
last row time, so the same three hours give one day. Weeks begin on
Sunday. A duration row time carries no calendar, so a unit
measures it only where a duration counts in that unit:
'secondly', 'minutely', 'hourly',
'daily' and 'yearly' are taken and 'weekly',
'monthly' and 'quarterly' are refused.
ttB = retime (ttA,
builds a grid from the first row time in steps of the
'regular', …)'TimeStep' or 'SampleRate' given after it, exactly one
of which is required. 'SampleRate' is in hertz. It is bounded
by the same rule.
method says how a row that the old times do not carry takes its
value. 'fillwithmissing' leaves it missing;
'previous', 'next' and 'nearest' copy a
neighbouring value; and 'linear', 'spline',
'pchip' and 'makima' interpolate, which restricts the
timetable to numeric, datetime and duration variables.
'default', which is also what no method at all means, reads
VariableContinuity and treats a 'continuous' variable
as 'linear', a 'step' one as 'previous', and
an 'unset' or 'event' one as
'fillwithmissing'.
method may instead aggregate the rows the target times gather
into each bin, as 'sum', 'prod', 'mean',
'median', 'mode', 'min', 'max',
'count', 'firstvalue' or 'lastvalue', or as a
function handle taking the rows of one bin and returning a single row.
A bin holding no row answers 0 for 'sum', 1 for
'prod', 0 for 'count' and missing for the rest, and a
function handle is called on it too, with an empty slice of the
variable’s own type. Every method but 'count',
'firstvalue' and 'lastvalue' needs a numeric,
logical, datetime or duration variable.
'IncludedEdge' says which edge of a bin belongs to it,
'left' by default, under which the last bin runs on past the
last target time; 'right' instead lets the first bin run back
before the first. A grid built from a unit or a step moves with it:
closed on the right it starts at the first bin that can hold a row and
ends one unit past the last row time. It is read only by an
aggregating method.
An option the chosen method cannot use is warned about and ignored rather than dropped in silence, once per call. MATLAB says nothing in that case.
An aggregation reads the row times as bins rather than as sample points, so it accepts row times that repeat and row times out of order, both of which the other methods refuse.
'fillwithconstant' gives every added row the value of
'Constant', which is required with it and must be a value of
the variable’s own kind: a number for a numeric or logical
variable, a duration for a duration one, and text for a
string or a categorical one, where a name the variable
does not yet carry is added to its categories. A number standing for
a duration or for text is refused rather than read as days or
as digits. Needing no missing value of its own, it serves a variable
that has none.
'EndValues' says what a target time outside the span of the
old ones takes, either 'extrap' or a constant. It is
'extrap' by default, under which 'linear' and the
interpolating methods extrapolate and the neighbouring methods carry
the nearest known value outward.
A value that was missing before the call is a gap like any
other and is filled with them: a row the new times keep is resampled
along with the rest, so 'previous' gives it the last value
that was not missing rather than the missing value it held. Only
'fillwithmissing' leaves such a value alone.
Every property of the timetable survives, VariableUnits,
VariableDescriptions and VariableContinuity included,
and the result carries the time step its new row times imply.
See also: timetable, isregular, fillmissing, synchronize
Source Code: timetable