主要内容

时间范围

时间表订阅时间表的时间范围

描述

例子

s = timerange(开始时间,末日创建一个下标,以在多个时间范围内选择时间表的行。sselects all rows whose times are in the time interval specified by开始时间and时间结束, 包含开始时间但不是时间结束。换句话说,时间间隔为半开间隔。开始时间and时间结束是DateTime或持续时间标量,或指定日期和时间的字符向量或字符串。

如果开始时间and时间结束是DateTime值,然后您只能使用s将订阅为一个时间表,其行时间是DateTime值。同样,如果开始时间and时间结束是持续时间值,然后您只能使用sto subscript into a timetable whose row times are duration values.

例子

s = timerange(开始时间,末日,,,,intervalType在指定的间隔类型上创建下标intervalType。例如,如果intervalType'关闭', 然后s包括两者开始时间and时间结束in the time range it specifies.

例子

s = timerange(Startperiod,,,,Endperiod,,,,Unitoftime在之间的时间段内创建下标StartperiodandEndperiod,使用由Unitoftime。例如,如果Unitoftime“月份”, 然后s包括本月的开始,是Startperiod,以及本月底Endperiod。The inputsStartperiodandEndperiodcan be datetime scalars, or if text, they can be character vectors or strings that specify dates and times.

例子

s = timerange(timePeriod,,,,Unitoftime创建一个跨越开始和结束的下标timePeriod,使用由Unitoftime。例如,如果Unitoftime'天', 然后sincludes the start and end of the day that is a component oftimePeriod

例子

全部收缩

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];压力= [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 =分类({'NW';'n';'NW';'NW';'nnw';'n'});tt =时间表(时间,温度,压力,风速,风速)
TT=6×4时间表时间温度压力风速风向____________________ ___________________________________________________________15-DEC-2015 08:00:00 37.3 30.1 13.4 NW 18-DEC-2015 10:00:00:00:00 39.1 39.1 39.1 30.1 30.03 6.5 N 6.5 N 6.5 N 6 6.5 N18-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

指定时间范围12/18/2015 08:00:00and12/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)请参见选择按行时间和可变的时间表数据类型。

选择与时间在指定范围内的行s。The output timetable includes the start of the time range, but not the end.

tt2 = tt(s,:)
tt2 =2×4时间表时间温度压力风速风向____________________ ___________________________________________________________15-DEC-2015 08:00:00 37.3 30.1 13.4 NW 18-DEC-2015 10:00:00:00:00 39.1 39.1 39.1 30.1 30.03 6.5 N 6.5 N 6.5 N 6 6.5 N

创建一个时间表。

时间= [秒(1):秒(1):秒(5)];tt =时间表(时间',[98; 97.5; 97.9; 98.1; 97.9],[120; 111; 119; 117; 117; 116] ,,...'variablenames',,,,{'Reading1',,,,'Reading2'})
TT=5×2时间表时间阅读1阅读2 _____ _________________________________________________ 97.5 111 3 sec 97.9 119 4 sec 98.1 117 5 sec 97.9 116

指定闭合时间间隔在两到四秒之间。

s = timerange(秒(2),秒(4),,'关闭'
s =时间表fimerange下标:在闭合间隔中选择时间表行:[2 sec,4 sec]请参阅“按行”和“变量类型”选择时间表数据。

选择与时间在指定范围内的行s。The closed interval includes both the start and end times.

tt2 = tt(s,:)
tt2 =3×2时间表时间阅读1阅读2 _____ _________________ 2秒97.5 111 3秒97.9 119 4 sec 98.1 117

Create a timetable containing prices set at the middle of each month.

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

使用“季度”作为时间单位。时间范围的开始是包括2018年1月1日的季度。该范围的结束是包括2018年5月1日的季度。时间范围包括整个季度,这意味着该范围的结束是瞬间2018年7月1日开始。

s = timerange('2018-01-01',,,,'2018-05-01',,,,“季度”
S =时间表timerange下标:选择timetable rows with times in: QUARTERS Starting at, including: 01-Jan-2018 00:00:00 Ending at, but excluding: 01-Jul-2018 00:00:00 See Select Timetable Data by Row Time and Variable Type.

选择行TT。输出时间表包括2018年5月15日和6月15日的行,而不是7月15日的行,或者在2018年前两个季度以外的时间。

TT(S,:)
ans =6×1 timetable时间价格___________ ______ 15-JAN-2018-2018 106 15-FEB-2018 108 108 15-MAR-2018 88 15-APR-2018 108 108 15-MAY-2018-2018 101 15-JUN-2018-2018 87

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

time = dateTime({'2018-01-01';'2018-01-15';'2018-02-01';'2018-02-15';'2018-03-01';'2018-03-15'});价格= randi([85 110],6,1);tt =时间表(时间,价格)
TT=6×1 timetable时间价格___________ ___________________2018 106 15-JAN-2018-2018 108 108 01-FEB-2018 88 15-FEB-2018 108 108 108 01-MAR-2018 101 15-MAR-2018 87 87 87

使用“月份”作为时间单位。由于第一个输入是2018年2月的日期,时间范围跨越了整个2月。

s = timerange('2018-02-01',,,,“月份”
S =时间表timerange下标:选择timetable rows with times in: MONTHS Starting at, including: 01-Feb-2018 00:00:00 Ending at, but excluding: 01-Mar-2018 00:00:00 See Select Timetable Data by Row Time and Variable Type.

选择行TT

TT(S,:)
ans =2×1 timetableTime Price ___________ _____ 01-Feb-2018 88 15-Feb-2018 108

输入参数

全部收缩

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

如果开始时间and时间结束are character vectors or string scalars, then they specify dates and times. If开始时间and时间结束有格式时间范围does not recognize, then convert them to datetime or duration values using the约会时间or期间功能。使用“ inputformat'争论约会时间or期间

要创建单方面的时间范围,请使用'-inf'or'inf'as start or end times. The syntaxtimerange(' - inf',末日)specifies all dates and times before时间结束, 尽管timerange(开始时间,'inf')指定所有日期和时间之后开始时间

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

Interval Type

描述

'打开'

选择满足开放间隔的时间的行Starttime andROWTIME

'关闭'

选择满足封闭间隔的时间的行Starttime <= RowtimeandRowtime <=末日

“开放式”

选择满足半开间隔的时间的行Starttime andRowtime <=末日

“ openright'(默认)

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

``封闭''

相当于“开放式”

“闭合”

相当于“ openright'

开始和结束时间段,指定为一对DateTime标量,或作为一对字符向量或字符串标量。

如果StartperiodandEndperiodare character vectors or string scalars, then they specify dates and times. IfStartperiodandEndperiod有格式时间范围does not recognize, then convert them to datetime values using the约会时间功能。使用“ inputformat'争论约会时间

要创建单方面的时间范围,请使用'-inf'or'inf'作为开始或结束期。例如,语法timerange(' - inf',endperiod,'days')指定一天结束前的所有日期和时间Endperiod。The syntax时间范围(startTime,'inf','days')指定当天开始之后的所有日期和时间Startperiod

时间段,指定为DateTime标量,字符向量或字符串标量。如果timePeriod是字符向量或字符串标量,然后指定一个日期和时间约会时间功能可以转换为DateTime值。

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

笔记:您可以指定Unitoftime仅当其他输入参数指定DateTime值而不是持续时间值时。

日期或时间组件

描述

'年'

select rows with times such that年(startperiod)<=年(行)and年(行)<=年(endperiod)

“季度”

select rows with times such that季度(startperiod)<=四分之一(行)and季度(行)<=季度(endperiod)

“月份”

select rows with times such that月份(startperiod)<=月(rowtime)and月(行)<=月(endperiod)

“周”

select rows with times such that周(startperiod)<=周(Rowtime)and周(行)<=周(endperiod)

'天'

select rows with times such thatDay(Startperiod)<= Day(Rowtime)and天(行)<=天(endperiod)

'小时'

select rows with times such that小时(startperiod)<=小时(Rowtime)and小时(行)<=小时(endperiod)

'分钟'

select rows with times such that分钟(startperiod)<= minute(Rowtime)and分钟(Rowtime)<=分钟(Endperiod)

“秒”

select rows with times such that第二个(startperiod)<= second(Rowtime)and第二个(Rowtime)<= second(endperiod)

扩展功能

在R2016b中引入