主要内容

withtol

Time tolerance for timetable row subscripting

Description

example

S = withtol(rowTimes,tol)creates a subscript to select rows of a timetable.Sselects all rows whose row times match a time inrowTimeswithin the tolerance specified bytol。这rowTimesargument is a datetime or duration array, or a cell array of character vectors that specify dates and times.tolmust be a duration value.

IfrowTimescontains datetime values, then you can only useSto subscript into a timetable whose row times are datetime values. Similarly, ifrowTimescontains duration values, then you can only useS将订阅为一个时间表,其行时间为持续时间值。

Examples

collapse all

Create a timetable that contains temperature and pressure data with row times in hours. There is a slight random variance in the row times. Select rows with row times that match corresponding times in a time vector within a tolerance of five seconds.

Time = datetime(2015,12,18) + hours(1:10)' + seconds(randn(10,1)); Temp = [37.3 39.1 42.3 42.6 43 43.9 44.1 43.3 42.5 42]'; Pressure = [29.4 29.6 30.0 30.0 30.1 29.9 29.9 29.8 29.6 29.7]'; TT = timetable(Time,Temp,Pressure)
tt =10×2 timetableTime Temp Pressure ____________________ ____ ________ 18-Dec-2015 01:00:00 37.3 29.4 18-Dec-2015 02:00:01 39.1 29.6 18-Dec-2015 02:59:57 42.3 30 18-Dec-2015 04:00:00 42.6 30 18-Dec-2015 05:00:00 43 30.1 18-Dec-2015 05:59:58 43.9 29.9 18-Dec-2015 06:59:59 44.1 29.9 18-Dec-2015 08:00:00 43.3 29.8 18-Dec-2015 09:00:03 42.5 29.6 18-Dec-2015 10:00:02 42 29.7

创建一个时间矢量,涉及从3:00到8:00的小时。

newTimes = datetime(2015,12,18) + hours(3:8)
newTimes =1x6 datetimeColumns 1 through 3 18-Dec-2015 03:00:00 18-Dec-2015 04:00:00 18-Dec-2015 05:00:00 Columns 4 through 6 18-Dec-2015 06:00:00 18-Dec-2015 07:00:00 18-Dec-2015 08:00:00

Select rows ofTTwith row times that match times innewTimes在五seconds.

S = withtol(newTimes,seconds(5)); TT2 = TT(S,:)
TT2=6×2 timetableTime Temp Pressure ____________________ ____ ________ 18-Dec-2015 02:59:57 42.3 30 18-Dec-2015 04:00:00 42.6 30 18-Dec-2015 05:00:00 43 30.1 18-Dec-2015 05:59:58 43.9 29.9 18-Dec-2015 06:59:59 44.1 29.9 18-Dec-2015 08:00:00 43.3 29.8

Input Arguments

collapse all

Times to match in a timetable, specified as a datetime array, duration array, cell array of character vectors, or string array.rowTimescontains times that do not exactly match times in the row times of a timetable, but that might be within a specified tolerance.

IfrowTimes是字符向量或字符串数​​组的单元格数组,然后数组的元素指定日期和时间约会时间或者durationfunctions can convert.

匹配时间到时间表的行时间的公差,指定为持续时间,字符向量或字符串标量。

Iftol是字符向量或字符串标量,然后tol指定时间duration功能可以转换。

Extended Capabilities

C/C++ Code Generation
使用MATLAB®CODER™生成C和C ++代码。

Introduced in R2016b