mustBeNonzero

Checks that no element is zero.

Category: Programming > Functions

Syntax

mustBeNonzero(A)

Checks that no element of A is zero. Returns nothing if the check passes and throws an error if not.

Description

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

Positive and negative values both pass. It is useful for arguments that will be used as divisors.

Input arguments

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

Example

Passing and failing input

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

See also

mustBePositive mustBeNegative mustBeNonempty nnz