mustBeLessThan
Checks that every element is strictly less than a bound.
Category: Programming > Functions
Syntax
mustBeLessThan(A, c)
Checks that every element of A is strictly less than c. Returns nothing if the check passes and throws an error if not.
Description
mustBeLessThan is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeLessThan. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.
Each element is compared with the scalar c using <. Any element that fails the comparison makes the whole call error.
Input arguments
A- The value to check. Any array of the class the validator accepts.
c- Scalar bound to compare against.
Example
Passing and failing input
mustBeLessThan([1 2 3], 5);
disp('passed')
try
mustBeLessThan([1 9 2], 5)
catch err
disp(err.message)
end
Output
passed
Value must be less than 5.
See also
mustBeLessThanOrEqual mustBeGreaterThan mustBeNegative mustBeInRange