withtol
Selects timetable rows whose times are close to given times, within a tolerance.
Category: Language Fundamentals > Data Types
Syntax
s = withtol(times, tol)
Creates a subscript that matches row times within tol of any of times.
Description
Exact comparison of times is fragile when they come from sampling or rounding. withtol lets you ask for "the rows near 5 seconds" without writing the arithmetic yourself. Several target times can be given at once, and every row near any of them is selected.
The object does nothing on its own; it only has meaning as a row subscript of a timetable.
Input arguments
times- Target times, as
datetimeordurationvalues, matching the type of the row times. tol- Tolerance as a
duration. A row matches when its time differs from a target by at mosttol.
Output arguments
s- A timetable subscript object, used inside the parentheses:
TT(s, :).
Example
TT = timetable(seconds([1;5;9]), [1;2;3]);
TT(withtol(seconds(5.2), seconds(0.5)), :)
TT(withtol(seconds([1 9]), seconds(1)), :)
Output
ans = 1×1 timetable
Time Var1
_____ ____
5 sec 2
ans = 2×1 timetable
Time Var1
_____ ____
1 sec 1
9 sec 3