主要内容

时间范围

时间范围为时间表row subscripting

描述

example

S = timerange(开始时间,endTime)创建一个下标,以在多个时间范围内选择时间表的行。S选择所有在按时间间隔中指定的时间的行开始时间endTime, 包含开始时间but notendTime。In other words, the time interval is a half-open interval.开始时间endTimeare datetime or duration scalars, or character vectors or strings that specify dates and times.

如果开始时间endTime是DateTime值,然后您只能使用S将订阅为一个时间表,其行时间是DateTime值。同样,如果开始时间endTimeare duration values, then you only can useS将订阅为一个时间表,其行时间为持续时间值。

example

S = timerange(开始时间,endTime,间隔类型)在指定的间隔类型上创建下标间隔类型。例如,如果间隔类型'closed', thenSincludes both开始时间endTime在指定的时间范围内。

example

S = timerange(startperiod,endperiod,unitOfTime)在之间的时间段内创建下标startPeriodEndperiod,使用由unitOfTime。例如,如果unitOfTime“月份”, thenS包括本月的开始,是startPeriod, and the end of the month ofEndperiod。输入startPeriodEndperiod可以是DateTime标量,或者如果文本,则可以是指定日期和时间的字符向量或字符串。

example

S = timerange(时间段,unitOfTime)创建一个跨越开始和结束的下标时间段,使用由unitOfTime。例如,如果unitOfTime'day', thenS包括一天的开始和结束,这是时间段

例子

全部收缩

创建一个时间表,其中包含时间,并测量温度,压力和风速和方向。选择其时间落在指定时间间隔内的行。

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 =时间表(时间,温度,压力,风速,风速)
tt =6×4时间表时间温度压力风速风向____________________ _________________________________________________________________15-DEC-2015 08:00 08:00 37.3 30.1 13.4 NW 18-DEC-2015 10:00:00 10:00 39.1 39.1 39.1 39.1 30.03 6.5 N 18-DEC-2015 12:00:00 42.00 42.3 29.97.3 NW 18-DEC-2015 14:00 45.7 29.8 8.5 NW 18-DEC-2015 16:00:00 41.2 30 9.2 NNW 18-DEC-2015-2015 18:00:00:00 39.9 29.9 29.9 4.3 4.3 N 4.3 N 4.3 N N.3

Specify a time range between12/18/2015 08:00:0012/18/2015 12:00:00

S = timerange('12/18/2015 08:00:00','12/18/2015 12:00:00')
s =时间表fimerange下标:在半开间间隔时间内选择时间表行:[18-dec-2015 08:00:00,18-dec-2015 12:00:00)请参见选择按行时间和可变的时间表数据类型。

Select rows with times in the range specified byS。输出时间表包括时间范围的开始,但不包括末端。

TT2 = TT(S,:)
TT2=2×4 timetableTime 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

创建一个时间表。

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 =5×2 timetableTime 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

Specify a closed time interval between two and four seconds.

S = timerange(seconds(2),seconds(4),'closed')
S = timetable timerange subscript: Select timetable rows with times in the closed interval: [2 sec, 4 sec] See Select Timetable Data by Row Time and Variable Type.

Select rows with times in the range specified byS。封闭的间隔包括开始时间和结束时间。

TT2 = TT(S,:)
TT2=3×2 timetableTime Reading1 Reading2 _____ ________ ________ 2 sec 97.5 111 3 sec 97.9 119 4 sec 98.1 117

创建一个时间表,其中包含每个月中旬设定的价格。

Time = datetime(2018,1:12,15)'; Price = randi([85 110],12,1); TT = timetable(Time,Price)
tt =12×1 timetable时间价格___________ ______ 15-17-17-15-15-FEB-2018 108 108 108 15-MAR-2018 88 15-APR-2018 108 108 15-MAY-2018-2018 101 15-JUN-2018-2018 87 87 15-JUL-2018 92 15-2018 15-EAGE-EAGE-EAGE-2018-EAGE-2018 99 15-Sep-2018 109 15-OCT-2018 110 110 15-NOV-2018 89 15-DEC-2018 110

Specify a time range using'quarters'作为时间单位。时间范围的开始是包括2018年1月1日的季度。该范围的结束是包括2018年5月1日的季度。时间范围包括整个季度,这意味着该范围的结束是瞬间2018年7月1日开始。

S = timerange('2018-01-01','2018-05-01','quarters')
s =时间表时间表下标:选择时间表行,以下时间:季度开始,包括:01-1月1日至2018年1月00:00:00结束,但排除:01-Jul-2018 00:00:00:00请参阅SELECTESTABL行时间和可变类型。

Select rows ofTT。The output timetable includes the rows for May 15 and June 15, 2018, but not the row for July 15, or any row with a time outside the first two quarters of 2018.

tt(s,:)
ans =6×1时间表Time Price ___________ _____ 15-Jan-2018 106 15-Feb-2018 108 15-Mar-2018 88 15-Apr-2018 108 15-May-2018 101 15-Jun-2018 87

创建一个时间表,其中包含在每个月开始和中旬设定的价格。

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时间表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 time range using“月份”作为时间单位。由于第一个输入是2018年2月的日期,时间范围跨越了整个2月。

S = timerange('2018-02-01',“月份”)
s =时间表时间表下标:选择时间表行与以下时间:从以下时间开始,包括:01-feb-2018 00:00:00:00结束,但排除:01-MAR-2018 00:00:00:00请参阅选择按时间表数据,请参阅选择时间表数据。行时间和可变类型。

Select rows ofTT

tt(s,:)
ans =2×1时间表时间价格___________ ______ 01-FEB-2018 88 15-FEB-2018 108

输入参数

全部收缩

开始和结束时间范围,指定为一对DateTime或持续时间标量,或一对字符向量或字符串标量。

如果开始时间endTime是字符向量或字符串标量,然后指定日期和时间。如果开始时间endTimehave formats that时间范围不识别,然后使用它们转换为日期时间或持续时间值约会时间或者durationfunction. Specify the format using the“ inputformat'争论约会时间或者duration

要创建单方面的时间范围,请使用'-inf'或者'inf'作为开始或结束时间。语法timerange(' - inf',末日)指定之前的所有日期和时间endTime, whiletimerange(开始时间,'inf')指定所有日期和时间之后开始时间

时间范围间隔的类型,指定为字符向量或字符串标量。该表显示了时间范围间隔的类型。

间隔类型

描述

'打开'

选择满足开放间隔的时间的行开始时间< rowTimerowTime < endTime

'closed'

Select rows with times that satisfy the closed intervalStarttime <= RowtimerowTime <= endTime

'openleft'

选择满足半开间隔的时间的行开始时间< rowTimerowTime <= endTime

'openright'(默认)

选择满足半开间隔的时间的行Starttime <= RowtimerowTime < endTime

'closedright'

相当于'openleft'

'closedleft'

相当于'openright'

Start and end time periods, specified as a pair of datetime scalars, or as a pair of character vectors or string scalars.

如果startPeriodEndperiod是字符向量或字符串标量,然后指定日期和时间。如果startPeriodEndperiodhave formats that时间范围不识别,然后使用约会时间function. Specify the format using the“ inputformat'争论约会时间

要创建单方面的时间范围,请使用'-inf'或者'inf'as start or end periods. For example, the syntaxtimerange(' - inf',endperiod,'days')指定一天结束前的所有日期和时间Endperiod。语法timerange(开始时间,“ inf”,“ days”)指定所有日期和时间之后the start of the day ofstartPeriod

时间段, specified as a datetime scalar, character vector, or string scalar. If时间段是字符向量或字符串标量,然后指定一个日期和时间约会时间功能可以转换为DateTime值。

时间段的组件,指定为字符向量或字符串标量。该表显示您可以指定的组件。

Note:You can specifyunitOfTime仅当其他输入参数指定DateTime值而不是持续时间值时。

Date or Time Component

描述

'years'

选择时间的行年(startperiod)<=年(行)年(行)<=年(endperiod)

'quarters'

选择时间的行quarter(startPeriod) <= quarter(rowTime)quarter(rowTime) <= quarter(endPeriod)

“月份”

选择时间的行月份(startperiod)<=月(rowtime)month(rowTime) <= month(endPeriod)

'weeks'

选择时间的行week(startPeriod) <= week(rowTime)周(行)<=周(endperiod)

'days'

选择时间的行day(startPeriod) <= day(rowTime)天(行)<=天(endperiod)

'小时'

选择时间的行小时(startperiod)<=小时(Rowtime)hour(rowTime) <= hour(endPeriod)

'minutes'

选择时间的行分钟(startperiod)<= minute(Rowtime)minute(rowTime) <= minute(endPeriod)

'seconds'

选择时间的行second(startPeriod) <= second(rowTime)second(rowTime) <= second(endPeriod)

Extended Capabilities

Version History

Introduced in R2016b