timetable.withinrange
timetable: TF = withinrange (tt, ref)
timetable: [TF, whichRows] = withinrange (tt, ref)
True when the whole range of a timetable lies inside a range of times.
TF = withinrange (tt, ref) returns true when
every row time of tt lies inside ref, which is to say that
its earliest and its latest row time both do.
Whether the ends themselves count is ref’s to say, and this is
where it tells. A timerange is half open by default, excluding
the time it ends at, so a timetable whose last row falls exactly on
that time is not within it; the same range built closed
contains that instant, and the answer turns true.
ref takes the same three forms as in containsrange: a
timerange, a timetable whose earliest and latest row
times give the range, or a datetime or duration scalar
naming one instant. A timetable is within a single instant only when
every row time it has is that instant.
[TF, whichRows] = withinrange (…) also returns
a column of logicals saying which rows of tt fall in ref.
When TF is true they are all true, this being the one predicate
for which the two answers agree.
See also: containsrange, overlapsrange, timerange, timetable
Source Code: timetable
withinrange asks whether the whole of a timetable lies inside a range of times. A timerange is half open by default, excluding the time it ends at, so a timetable whose last row falls exactly there is not within it.
t0 = datetime (2024, 1, 1); Load = [220; 245; 260; 255; 231; 219]; TT = timetable (Load, 'RowTimes', t0 + hours (0:5)')
TT =
6x1 timetable
Time Load
____________________ ____
01-Jan-2024 00:00:00 220
01-Jan-2024 01:00:00 245
01-Jan-2024 02:00:00 260
01-Jan-2024 03:00:00 255
01-Jan-2024 04:00:00 231
01-Jan-2024 05:00:00 219
withinrange (TT, timerange (t0, t0 + hours (5)))
ans = 0
Close that same range and the last row is inside it.
withinrange (TT, timerange (t0, t0 + hours (5), 'closed'))
ans = 1
The three predicates answer three different questions about the same pair of ranges. A range wider than the timetable is one the timetable lies within and one it does not contain.
t0 = datetime (2024, 1, 1);
TT = timetable ([220; 245; 260], 'RowTimes', t0 + hours (0:2)', ...
'VariableNames', {'Load'});
R = timerange (t0 - hours (1), t0 + hours (9));
containsrange (TT, R)
ans = 0
overlapsrange (TT, R)
ans = 1
withinrange (TT, R)
ans = 1