mustBeLessThanOrEqual
Checks that every element is less than or equal to a bound.
Category: Programming > Functions
Syntax
mustBeLessThanOrEqual(A, c)
Checks that every element of A is less than or equal to c. Returns nothing if the check passes and throws an error if not.
Description
mustBeLessThanOrEqual is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeLessThanOrEqual. 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
mustBeLessThanOrEqual([1 2 5], 5);
disp('passed')
try
mustBeLessThanOrEqual([1 9 2], 5)
catch err
disp(err.message)
end
Output
passed
Value must be less than or equal to 5.
See also
mustBeLessThan mustBeGreaterThanOrEqual mustBeNonpositive mustBeInRange