timetable.overlapsrange
timetable: TF = overlapsrange (tt, ref)
timetable: [TF, whichRows] = overlapsrange (tt, ref)
True when a timetable and a range of times have any instant in common.
TF = overlapsrange (tt, ref) returns true when
the range of tt, from its earliest to its latest row time, shares
at least one instant with ref. Meeting at a single instant is
enough: a range that starts exactly at the last row time overlaps.
Whether the ends themselves count is ref’s to say. A
timerange that excludes its lower bound does not overlap a
timetable that reaches only as far as that bound.
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.
[TF, whichRows] = overlapsrange (…) also
returns a column of logicals saying which rows of tt fall in
ref. A timetable can overlap a range without any of its rows
falling in it, the overlap being of the ranges and not of the rows.
See also: containsrange, withinrange, timerange, timetable
Source Code: timetable
overlapsrange asks whether a timetable and a range of times share any instant at all. Meeting at a single one is enough, so a range that starts exactly at the last row time still overlaps.
t0 = datetime (2024, 1, 1); Flow = [3.1; 3.4; 4.0; 3.8; 3.2; 2.9]; TT = timetable (Flow, 'RowTimes', t0 + hours (0:5)')
TT =
6x1 timetable
Time Flow
____________________ ____
01-Jan-2024 00:00:00 3.1
01-Jan-2024 01:00:00 3.4
01-Jan-2024 02:00:00 4
01-Jan-2024 03:00:00 3.8
01-Jan-2024 04:00:00 3.2
01-Jan-2024 05:00:00 2.9
overlapsrange (TT, timerange (t0 + hours (5), t0 + hours (9)))
ans = 1
Move the range one hour later and nothing is shared.
overlapsrange (TT, timerange (t0 + hours (6), t0 + hours (9)))
ans = 0
Overlap is of the ranges, not of the rows, so a timetable can overlap a range without a single row falling in it. The two outputs disagree here and both are right.
t0 = datetime (2024, 1, 1);
TT = timetable ([3.1; 4.0; 2.9], 'RowTimes', t0 + hours ([0 3 6])', ...
'VariableNames', {'Flow'});
[tf, whichRows] = overlapsrange (TT, timerange (t0 + hours (1), ...
t0 + hours (2)))
tf = 1 whichRows = 0 0 0