mustBeNegative
Checks that every element is less than zero.
Category: Programming > Functions
Syntax
mustBeNegative(A)
Checks that every element of A is negative. Returns nothing if the check passes and throws an error if not.
Description
mustBeNegative is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeNegative. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.
Zero is not negative, so it fails. Use mustBeNonpositive to accept zero as well.
Input arguments
A- The value to check. Any array of the class the validator accepts.
Example
Passing and failing input
mustBeNegative([-3 -1]);
disp('passed')
try
mustBeNegative([-3 0])
catch err
disp(err.message)
end
Output
passed
Value must be negative.
See also
mustBeNonpositive mustBePositive mustBeLessThan mustBeNonzero