withtol
时间表行下标的时间容差
说明
S = withtol(
使用事件过滤器创建行下标。要使用事件过滤器,您通过下标对其进行索引的时间表必须有附加的事件表。有关使用事件过滤器指定时间容差的详细信息,请参阅 EF
,tol
)eventfilter
。 (自 R2023a 起)
示例
指定用于匹配行时间的容差
创建包含温度和压力数据且行时间以小时为单位的时间表。行时间中会有轻微的随机变化。选择行时间与时间向量中的对应时间相匹配的行,容差范围为五秒。
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 timetable
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 = 1x6 datetime
18-Dec-2015 03:00:00 18-Dec-2015 04:00:00 18-Dec-2015 05:00:00 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=6×2 timetable
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
输入参数
rowTimes
— 要在时间表中匹配的时间
日期时间数组 | 持续时间数组 | 字符向量元胞数组 | 字符串数组
要在时间表中匹配的时间,指定为日期时间数组、持续时间数组、字符向量元胞数组或字符串数组。rowTimes
包含的时间不完全匹配时间表的行时间中的时间,但可能在指定的容差范围内。
如果 rowTimes
是字符向量元胞数组或字符串数组,则数组的元素指定 datetime
或 duration
函数可以转换的日期时间。
tol
— 用于将时间与时间表的行时间进行匹配的容差
持续时间 | 字符向量 | 字符串标量
用于将时间与时间表的行时间进行匹配的容差,指定为持续时间、字符向量或字符串标量。
如果 tol
是字符向量或字符串标量,则 tol
指定 duration
函数可以转换的时间。
EF
— 事件过滤器
事件过滤器
自 R2023a 起
事件过滤器。
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
用法说明和限制:
不支持事件过滤器。
有关详细信息,请参阅Code Generation for Timetables (MATLAB Coder)和Timetable Limitations for Code Generation (MATLAB Coder)。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
版本历史记录
在 R2016b 中推出R2023a: 指定使用事件过滤器的时间容差
当您调用 withtol
时,您可以指定时间容差,用于查找事件过滤器找到的事件周围的行。要使用事件过滤器,您必须首先将事件表附加到输入时间表。有关事件表和事件过滤器的详细信息,请参阅 eventtable
和 eventfilter
。
R2023a: 改进了使用 withtol
下标对时间表进行索引时的性能
与在 R2022b 中相比,在 R2023a 中使用 withtol
下标对 timetable
进行下标索引时速度更快。
当您对一个包含 107 个行的时间表使用
withtol
下标进行索引时,在 R2023a 中的性能比在 R2022b 中大约快 44 倍。function timingTest() rng default % 10^7 rows N = 10000000; rowtimes = seconds(0:N-1); tt = timetable(rand(N,1),RowTimes=rowtimes); % 100 values chosen in steps of 10 n = 1000; t = seconds(0:10:n-1); tt.Time = tt.Time + .1*seconds(rand(N,1)); wt = withtol(t,seconds(.1)); tic tt2 = tt(wt,:); toc end
大致的执行时间是:
R2022b:3.92 秒
R2023a:0.09 秒
此代码是在 Windows® 10 的AMD® EPYC 74F3 24 核处理器 @ 3.19 GHz 测试系统上,通过调用每个版本的 timingTest
函数计时的。
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
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: .
You can also select a web site from the following list:
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.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)