Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

timerange

Time range for timetable row subscripting

Syntax

S = timerange(startTime,endTime)
S = timerange(startTime,endTime,intervalType)

Description

example

S = timerange(startTime,endTime) creates a subscript to select rows of a timetable within a range of times. S selects all rows whose times are in the time interval specified by startTime and endTime, including startTime but not endTime. In other words, the time interval is a half-open interval. startTime and endTime are either datetime or duration scalars, or character vectors that specify dates and times.

If startTime and endTime are datetime values, then you only can use S to subscript into a timetable whose row times are datetime values. Similarly, if startTime and endTime are duration values, then you only can use S to subscript into a timetable whose row times are duration values.

example

S = timerange(startTime,endTime,intervalType) creates a subscript over the type of interval specified by intervalType. For example, if intervalType is 'closed', then S includes both startTime and endTime in the time range it specifies.

Examples

collapse all

Create a timetable that contains times along with measurements of temperature, pressure, and wind speed and direction. Select rows whose times fall within a specified time interval.

Time = datetime({'12/18/2015 08:00:00';'12/18/2015 10:00:0';'12/18/2015 12:00:00';...
                 '12/18/2015 14:00:00';'12/18/2015 16:00:00';'12/18/2015 18:00:00'});
Temp = [37.3;39.1;42.3;45.7;41.2;39.9];
Pressure = [30.1;30.03;29.9;29.8;30.0;29.9];
WindSpeed = [13.4;6.5;7.3;8.5;9.2;4.3];
WindDirection = categorical({'NW';'N';'NW';'NW';'NNW';'N'});
TT = timetable(Time,Temp,Pressure,WindSpeed,WindDirection)
TT=6x4 timetable
            Time            Temp    Pressure    WindSpeed    WindDirection
    ____________________    ____    ________    _________    _____________

    18-Dec-2015 08:00:00    37.3     30.1       13.4         NW           
    18-Dec-2015 10:00:00    39.1    30.03        6.5         N            
    18-Dec-2015 12:00:00    42.3     29.9        7.3         NW           
    18-Dec-2015 14:00:00    45.7     29.8        8.5         NW           
    18-Dec-2015 16:00:00    41.2       30        9.2         NNW          
    18-Dec-2015 18:00:00    39.9     29.9        4.3         N            

Specify a time range between 12/18/2015 08:00:00 and 12/18/2015 12:00:00. The output timetable includes the start of the time range, but not the end.

S = timerange('12/18/2015 08:00:00','12/18/2015 12:00:00');
TT2 = TT(S,:)
TT2=2x4 timetable
            Time            Temp    Pressure    WindSpeed    WindDirection
    ____________________    ____    ________    _________    _____________

    18-Dec-2015 08:00:00    37.3     30.1       13.4         NW           
    18-Dec-2015 10:00:00    39.1    30.03        6.5         N            

Create a timetable.

Time = [seconds(1):seconds(1):seconds(5)];
TT = timetable(Time',[98;97.5;97.9;98.1;97.9],[120;111;119;117;116],...
               'VariableNames',{'Reading1','Reading2'})
TT=5x2 timetable
     Time    Reading1    Reading2
    _____    ________    ________

    1 sec      98        120     
    2 sec    97.5        111     
    3 sec    97.9        119     
    4 sec    98.1        117     
    5 sec    97.9        116     

Select rows that fall within a closed time interval between two and four seconds. The closed interval includes both the start and end times.

S = timerange(seconds(2),seconds(4),'closed');
TT2 = TT(S,:)
TT2=3x2 timetable
     Time    Reading1    Reading2
    _____    ________    ________

    2 sec    97.5        111     
    3 sec    97.9        119     
    4 sec    98.1        117     

Input Arguments

collapse all

Start and end times of time range, specified as a pair of datetime or duration scalars, or as a pair of character vectors.

If startTime and endTime are character vectors, then the character vectors specify dates and times that the datetime function can convert into datetime values.

Type of time range interval, specified as a character vector. The table shows the types of time range intervals.

Interval Type

Description

'open'

Select rows with times that satisfy the open interval startTime < rowTime and rowTime < endTime

'closed'

Select rows with times that satisfy the closed interval startTime <= rowTime and rowTime <= endTime

'openleft'

Select rows with times that satisfy the half-open interval startTime < rowTime and rowTime <= endTime

'openright' (default)

Select rows with times that satisfy the half-open interval startTime <= rowTime and rowTime < endTime

'closedright'

Equivalent to 'openleft'

'closedleft'

Equivalent to 'openright'

Introduced in R2016b

Was this topic helpful?