时间范围
时间范围为时间表row subscripting
Syntax
描述
S = timerange(
创建一个下标,以在多个时间范围内选择时间表的行。开始时间,endTime
)S
选择所有在按时间间隔中指定的时间的行开始时间
和endTime
, 包含开始时间
but notendTime
。In other words, the time interval is a half-open interval.开始时间
和endTime
are datetime or duration scalars, or character vectors or strings that specify dates and times.
如果开始时间
和endTime
是DateTime值,然后您只能使用S
将订阅为一个时间表,其行时间是DateTime值。同样,如果开始时间
和endTime
are duration values, then you only can useS
将订阅为一个时间表,其行时间为持续时间值。
S = timerange(
在指定的间隔类型上创建下标开始时间,endTime
,间隔类型
)间隔类型
。例如,如果间隔类型
是'closed'
, thenS
includes both开始时间
和endTime
在指定的时间范围内。
S = timerange(
在之间的时间段内创建下标startperiod,endperiod
,unitOfTime
)startPeriod
和Endperiod
,使用由unitOfTime
。例如,如果unitOfTime
是“月份”
, thenS
包括本月的开始,是startPeriod
, and the end of the month ofEndperiod
。输入startPeriod
和Endperiod
可以是DateTime标量,或者如果文本,则可以是指定日期和时间的字符向量或字符串。
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:00
和12/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
指定时间段from One Date
创建一个时间表,其中包含在每个月开始和中旬设定的价格。
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
输入参数
开始时间,endTime
—开始和结束时间范围
一对DateTime标量|一对持续时间标量|一对角色向量|一对弦标量
开始和结束时间范围,指定为一对DateTime或持续时间标量,或一对字符向量或字符串标量。
如果开始时间
和endTime
是字符向量或字符串标量,然后指定日期和时间。如果开始时间
和endTime
have formats that时间范围
不识别,然后使用它们转换为日期时间或持续时间值约会时间
或者duration
function. Specify the format using the“ inputformat'
争论约会时间
或者duration
。
要创建单方面的时间范围,请使用'-inf'
或者'inf'
作为开始或结束时间。语法timerange(' - inf',末日)
指定之前的所有日期和时间endTime
, whiletimerange(开始时间,'inf')
指定所有日期和时间之后开始时间
。
间隔类型
—Type of time range interval
角色向量|string scalar
时间范围间隔的类型,指定为字符向量或字符串标量。该表显示了时间范围间隔的类型。
间隔类型 |
描述 |
---|---|
|
选择满足开放间隔的时间的行 |
|
Select rows with times that satisfy the closed interval |
|
选择满足半开间隔的时间的行 |
|
选择满足半开间隔的时间的行 |
|
相当于 |
|
相当于 |
startperiod,endperiod
—Start and end time periods
一对DateTime标量|一对角色向量|一对弦标量
Start and end time periods, specified as a pair of datetime scalars, or as a pair of character vectors or string scalars.
如果startPeriod
和Endperiod
是字符向量或字符串标量,然后指定日期和时间。如果startPeriod
和Endperiod
have 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
。
时间段
—时间段
约会时间scalar|角色向量|string scalar
时间段, specified as a datetime scalar, character vector, or string scalar. If时间段
是字符向量或字符串标量,然后指定一个日期和时间约会时间
功能可以转换为DateTime值。
unitOfTime
—Component of time periods
角色向量|string scalar
时间段的组件,指定为字符向量或字符串标量。该表显示您可以指定的组件。
Note:You can specifyunitOfTime
仅当其他输入参数指定DateTime值而不是持续时间值时。
Date or Time Component |
描述 |
---|---|
|
选择时间的行 |
|
选择时间的行 |
|
选择时间的行 |
|
选择时间的行 |
|
选择时间的行 |
|
选择时间的行 |
|
选择时间的行 |
|
选择时间的行 |
Extended Capabilities
C/C ++代码生成
使用MATLAB®CODER™生成C和C ++代码。
用法注释和限制:
The input argument
unitOfTime
是not supported.
有关更多信息,请参阅时间表的代码生成(MATLAB编码器)和Timetable Limitations for Code Generation(MATLAB编码器)。
Version History
matlab命令
You clicked a link that corresponds to this MATLAB command:
通过在MATLAB命令窗口中输入该命令。Web浏览器不支持MATLAB命令。万博1manbetx
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
美洲
- AméricaLatina(Español)
- 加拿大(英语)
- 美国(英语)