创建包含温度和压力数据且行时间以小时为单位的时间表。行时间中会有轻微的随机变化。选择行时间与时间矢量中的对应时间相匹配的行,容差范围为五秒。
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 =
Time 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 =
1×6 datetime array
Columns 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
选择 TT 中行时间与 newTimes 中的时间相匹配的行,容差范围为五秒。
S = withtol(newTimes,seconds(5));
TT2 = TT(S,:)
TT2 =
Time 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