isbetween
Tests whether values lie within an interval, endpoints included.
Category: Language Fundamentals > Data Types
Syntax
tf = isbetween(x, lower, upper)
Returns true where lower <= x <= upper.
Description
isbetween is mostly used with dates: it saves writing x >= lower & x <= upper and reads clearly. Both limits are included. A value equal to either endpoint counts as inside.
Input arguments
xdatetime,duration(or numeric) array to test.lower, upper- Scalars or arrays of the same type, compatible in size with
x.
Output arguments
tf- Logical array.
Example
Dates in a month
t = datetime(2024, 1, [5 20 31]);
isbetween(t, datetime(2024, 1, 1), datetime(2024, 1, 25))
Output
ans = 1×3 logical array
1 1 0