overlapsrange - Determine if timetable row times overlap specified time range - MATLAB (original) (raw)
Determine if timetable row times overlap specified time range
Syntax
Description
[tf](#mw%5F22b86e5f-e81c-42ed-ae89-54f874b69356) = overlapsrange([TT](#mw%5Fa1480a56-42f3-4316-ace6-c11937e54156%5Fsep%5Fmw%5Ffce80f31-3ee4-439a-ba10-e9467a48c0bf),[rangeOfTimes](#mw%5Fa1480a56-42f3-4316-ace6-c11937e54156%5Fsep%5Fmw%5F5655f21f-c92b-4e87-9084-129ec9d920cc))
returns 1
(true
) if the range of the row times ofTT
intersects the time range specified byrangeOfTimes
. Otherwise, it returns 0
(false
).
The range of the row times of TT
is determined by its minimum and maximum row times.
[tf](#mw%5F22b86e5f-e81c-42ed-ae89-54f874b69356) = overlapsrange([TT](#mw%5Fa1480a56-42f3-4316-ace6-c11937e54156%5Fsep%5Fmw%5Ffce80f31-3ee4-439a-ba10-e9467a48c0bf),[oneTime](#mw%5Fa1480a56-42f3-4316-ace6-c11937e54156%5Fsep%5Fmw%5Fc5bc9496-6377-49b1-abb0-48d2e7a0696f))
determines if the range of row times of TT
contains the time specified byoneTime
.
[[tf](#mw%5F22b86e5f-e81c-42ed-ae89-54f874b69356),[whichRows](#mw%5Fa1480a56-42f3-4316-ace6-c11937e54156%5Fsep%5Fmw%5F6dfff7fd-1234-438a-99bc-6c63966f87fc)] = overlapsrange(___)
also returns logical indices indicating which rows of TT
are within the specified time range.
Examples
Create a timetable whose row times range from 0 seconds to 0.4 seconds.
Intensity = [100;98.7;95.2;101.4;99.1]; TT = timetable(Intensity,'TimeStep',seconds(0.1))
TT=5×1 timetable Time Intensity _______ _________
0 sec 100
0.1 sec 98.7
0.2 sec 95.2
0.3 sec 101.4
0.4 sec 99.1
Create a time range object with a range of 0.25–1.0 seconds. To create the object, use the timerange
function. Its inputs are durations, which you can create using the seconds
function.
rangeOfTimes = timerange(seconds(0.25),seconds(1.0))
rangeOfTimes = timetable timerange subscript:
Select timetable rows with times in the half-open interval:
Starting at, including: 0.25 sec
Ending at, but excluding: 1 sec
See Select Times in Timetable.
Determine if the row times of TT
overlap the range specified by rangeOfTimes
.
tf = overlapsrange(TT,rangeOfTimes)
Create another time range object with a range of 0.7–1.0 seconds. The overlapsrange
function returns 0, because rangeOfTimes
is entirely outside the time range of TT
.
rangeOfTimes = timerange(seconds(0.7),seconds(1.0))
rangeOfTimes = timetable timerange subscript:
Select timetable rows with times in the half-open interval:
Starting at, including: 0.7 sec
Ending at, but excluding: 1 sec
See Select Times in Timetable.
tf = overlapsrange(TT,rangeOfTimes)
Create two timetables with different time ranges. The timetables can also have different variables and different numbers of rows.
Intensity = [100;98.7;95.2;101.4;99.1]; TT1 = timetable(Intensity,'TimeStep',seconds(0.1))
TT1=5×1 timetable Time Intensity _______ _________
0 sec 100
0.1 sec 98.7
0.2 sec 95.2
0.3 sec 101.4
0.4 sec 99.1
Readings = [74;83;99]; TT2 = timetable(Readings,'TimeStep',seconds(0.5),'StartTime',seconds(0.25))
TT2=3×1 timetable Time Readings ________ ________
0.25 sec 74
0.75 sec 83
1.25 sec 99
Determine if the range of row times in TT1
overlaps the range of row times in TT2
.
tf = overlapsrange(TT1,TT2)
Create a timetable containing prices set at the beginning and middle of each month.
Time = datetime({'2018-01-01';'2018-01-15';'2018-02-01';'2018-02-15'; '2018-03-01';'2018-03-15'}); Price = randi([85 110],6,1); TT = timetable(Time,Price)
TT=6×1 timetable Time Price ___________ _____
01-Jan-2018 106
15-Jan-2018 108
01-Feb-2018 88
15-Feb-2018 108
01-Mar-2018 101
15-Mar-2018 87
Specify a point in time using the datetime
function. This time is midnight on February 1, 2018.
oneTime = datetime('2018-02-01')
oneTime = datetime 01-Feb-2018
Determine if the range of row times in TT
contains oneTime
.
tf = overlapsrange(TT,oneTime)
oneTime
does not have to match a specific row time of TT
. If oneTime
is any time between the minimum and maximum row times of TT
, then overlapsrange
returns 1.
oneTime = datetime('2018-02-28 09:23:45')
oneTime = datetime 28-Feb-2018 09:23:45
tf = overlapsrange(TT,oneTime)
Create a timetable.
Intensity = [100;98.7;95.2;101.4;99.1]; TT = timetable(Intensity,'TimeStep',seconds(0.1))
TT=5×1 timetable Time Intensity _______ _________
0 sec 100
0.1 sec 98.7
0.2 sec 95.2
0.3 sec 101.4
0.4 sec 99.1
Specify a time range. Then determine which rows of TT
are within the time range. The second output argument, whichRows
, is a logical array whose elements correspond to the rows in TT
. It contains 1
for each row whose row time is within the time range, and 0
for each row whose row time is not.
rangeOfTimes = timerange(seconds(0.1),seconds(0.35)); [tf,whichRows] = overlapsrange(TT,rangeOfTimes)
whichRows = 5×1 logical array
0 1 1 1 0
To access the rows within the time range, index into TT
using whichRows
.
TT2=3×1 timetable Time Intensity _______ _________
0.1 sec 98.7
0.2 sec 95.2
0.3 sec 101.4
Input Arguments
Input timetable. The minimum and maximum row times of TT
determine its range of times.
Time range, specified as a time range object or a timetable.
- If you specify
rangeOfTimes
as a time range object, then create the time range using thetimerange
function. Specify the beginning and end times of the range explicitly as inputs totimerange
.- If the input timetable
TT
has an attached event table, then you can calloverlapsrange
with a time range object that uses event filters. For more information on specifying a time range using event filters, see eventfilter (since R2023b)
- If the input timetable
- If you specify
rangeOfTimes
as a timetable, then you do not need to specify the beginning and end of the range explicitly.overlapsrange
gets them automatically from the minimum and maximum row times of the timetable.
A single time, specified as a datetime
or duration
scalar.
Output Arguments
True or false, returned as a logical 1
if the range of the row times of TT
intersects the time range specified byrangeOfTimes
or the point in time specified byoneTime
, and a logical 0
otherwise.
Indices of the rows within the specified time range, returned as a logical array. You can index into TT
using whichRows
.
For example, in this code you can use the second output of overlapsrange
to index into the timetable TT
. The timetable TT2
includes only those rows whose row times are within the range specified by rangeOfTimes
.
[tf,whichVars] = (TT,rangeOfTimes); TT2 = T(whichRows,:)
Extended Capabilities
Version History
Introduced in R2020a
When you call overlapsrange
, you can specify a time range that uses event filters as its start and end times. To use event filters, you must first attach an event table to the input timetable. For more information on usingoverlapsrange
with event filters, see eventfilter.