mustBeNonpositive

Checks that every element is zero or less.

Category: Programming > Functions

Syntax

mustBeNonpositive(A)

Checks that every element of A is less than or equal to zero. Returns nothing if the check passes and throws an error if not.

Description

mustBeNonpositive is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeNonpositive. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.

Zero passes. Use mustBeNegative when zero must be excluded.

Input arguments

A
The value to check. Any array of the class the validator accepts.

Example

Passing and failing input

mustBeNonpositive([-2 0]);
disp('passed')
try
    mustBeNonpositive(1)
catch err
    disp(err.message)
end
Output
passed
Value must not be positive.

See also

mustBeNegative mustBeNonnegative mustBeLessThanOrEqual mustBeNumeric