mustBeInRange - Validate that value is in the specified range - MATLAB (original) (raw)
Validate that value is in the specified range
Since R2020b
Syntax
Description
mustBeInRange([value](#mw%5F40763acb-331d-4697-9d57-41330c23e011),[lower](#mw%5F8765dc86-abf7-4707-9dd4-80f85ae427c3),[upper](#mw%5Fc9ee2b46-f711-4530-84b6-073f01b165ed))
throws an error if any element of value
is not within the range defined by lower
and upper
. A value is within the range if it is greater than or equal to lower
, and less than or equal toupper
. This function does not return a value.
mustBeInRange
calls these functions to determine if value
is in the specified range:
Class support: All numeric classes and logical.
mustBeInRange([value](#mw%5F40763acb-331d-4697-9d57-41330c23e011),[lower](#mw%5F8765dc86-abf7-4707-9dd4-80f85ae427c3),[upper](#mw%5Fc9ee2b46-f711-4530-84b6-073f01b165ed),[boundflag1](#mw%5Faea91e36-f2bd-4b3c-b953-6ee006687517),[boundflag2](#mw%5Faea91e36-f2bd-4b3c-b953-6ee006687517))
Uses optional flags boundflag1
and boundflag2
to indicate if the upper or lower bound is included in the range.
Examples
Use the mustBeInRange
function to restrict the range of allowed values.
Value must be greater than or equal to 0, and less than or equal to 1.
Values outside the range result in an error.
Input Arguments
Value to validate, specified as a scalar or array of numeric, logical, or user-defined types that support the relational operators, >
, >=
, <
, and <=
.
Lower bound of range, specified as a value of the same type as value.
Upper bound of range, specified as a value of the same type as value.
Include or exclude the upper or lower bound in the range, specified as one or two of the following:
inclusive
– Include the lower and upper values in the range of allowed values.exclusive
– Exclude thelower
andupper
values from the range of allowed values.exclude-lower
– Exclude thelower
value from the range of allowed values.exclude-upper
– Exclude theupper
value from the range of allowed values.
Use no more than two of these flags to indicate if the lower bound and upper bound should be excluded from or included in a range. The only valid combination of these flags is exclude-lower
and exclude-upper
. This combination is equivalent to using only exclusive
.
Data Types: char
| string
Tips
mustBeInRange
is designed to be used for property and function argument validation.
Extended Capabilities
The mustBeInRange
function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced in R2020b