时间范围
时间表订阅时间表的时间范围
句法
描述
s = timerange(
创建一个下标,以在多个时间范围内选择时间表的行。开始时间,末日
)s
selects all rows whose times are in the time interval specified by开始时间
and时间结束
, 包含开始时间
但不是时间结束
。换句话说,时间间隔为半开间隔。开始时间
and时间结束
是DateTime或持续时间标量,或指定日期和时间的字符向量或字符串。
如果开始时间
and时间结束
是DateTime值,然后您只能使用s
将订阅为一个时间表,其行时间是DateTime值。同样,如果开始时间
and时间结束
是持续时间值,然后您只能使用s
to 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
)Startperiod
andEndperiod
,使用由Unitoftime
。例如,如果Unitoftime
是“月份”
, 然后s
包括本月的开始,是Startperiod
,以及本月底Endperiod
。The inputsStartperiod
andEndperiod
can 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
是'天'
, 然后s
includes the start and end of the day that is a component oftimePeriod
。
例子
select Timetable Rows in Specified Time Interval
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:00
and12/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标量|一对持续时间标量|一对角色向量|一对弦标量
开始和结束时间范围,指定为一对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')
指定所有日期和时间之后开始时间
。
intervalType
-时间范围间隔
角色向量|字符串标量
时间范围间隔的类型,指定为字符向量或字符串标量。该表显示了时间范围间隔的类型。
Interval Type |
描述 |
---|---|
|
选择满足开放间隔的时间的行 |
|
选择满足封闭间隔的时间的行 |
|
选择满足半开间隔的时间的行 |
|
选择满足半开间隔的时间的行 |
|
相当于 |
|
相当于 |
Startperiod,,,,Endperiod
-开始和结束时间段
一对DateTime标量|一对角色向量|一对弦标量
开始和结束时间段,指定为一对DateTime标量,或作为一对字符向量或字符串标量。
如果Startperiod
andEndperiod
are character vectors or string scalars, then they specify dates and times. IfStartperiod
andEndperiod
有格式时间范围
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
。
timePeriod
-时间段
DateTime标量|角色向量|字符串标量
时间段,指定为DateTime标量,字符向量或字符串标量。如果timePeriod
是字符向量或字符串标量,然后指定一个日期和时间约会时间
功能可以转换为DateTime值。
Unitoftime
-时间段的组成部分
角色向量|字符串标量
时间段的组件,指定为字符向量或字符串标量。该表显示您可以指定的组件。
笔记:您可以指定Unitoftime
仅当其他输入参数指定DateTime值而不是持续时间值时。
日期或时间组件 |
描述 |
---|---|
|
select rows with times such that |
|
select rows with times such that |
|
select rows with times such that |
|
select rows with times such that |
|
select rows with times such that |
|
select rows with times such that |
|
select rows with times such that |
|
select rows with times such that |
扩展功能
C/C ++代码生成
使用MATLAB®CODER™生成C和C ++代码。
matlab命令
您单击了与此MATLAB命令相对应的链接:
通过在MATLAB命令窗口中输入该命令。Web浏览器不支持MATLAB命令。金宝app
您还可以从以下列表中选择一个网站:
如何获得最佳网站性能
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
美洲
- América Latina(Español)
- 加拿大(英语)
- 美国(英语)