INRANGE

INRANGE tests if values are within a specified range (interval).
1.1K Downloads
Updated 31 Mar 2016

View License

INRANGE tests if values are within a specified range (interval).
INRANGE(X,RANGE) tests if the values in X are within the range specified by RANGE. X can be a vector or matrix.

RANGE is a range in the form [LOW HIGH] against which each value in X will be tested. RANGE can also be a two-column vector whose ith row is of form RANGE(i,:) = [LOW HIGH]. In this form, input X must be a vector with the same length as RANGE, and each element of X is tested against the range in the corresponding row of RANGE.

INRANGE(X,RANGE,BOUNDARY) specifies whether the endpoints of the specified range should be included or excluded from the interval. The options for BOUNDARY are:

'includeboth' : Both end points included in interval (default)
'includeleft' : Left end point only included in interval
'includeright': Right end point only included in interval
'excludeboth' : Neither end point included in interval

If the LOW and HIGH values for RANGE are equal, that single value will be found in range only under the 'includeboth' option (default). Otherwise, for this case, no values will be found in range.

Examples:
X = 1:10
X =
1 2 3 4 5 6 7 8 9 10

Y = inrange(X,[5 7.2],'includeboth')
Y =
0 0 0 0 1 1 1 0 0 0

Y = inrange(X,[5 7.2],'excludeboth')
Y =
0 0 0 0 0 1 1 0 0 0

See also ISVALID.

Cite As

David Fass (2024). INRANGE (https://www.mathworks.com/matlabcentral/fileexchange/12591-inrange), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP3
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Test Scripts in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0

Made most of the fixes suggested by "Jos x" (thanks!). See M-file help.
Update for BSD license.