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