mustBeNonNan
Checks that no element is NaN.
Category: Programming > Functions
Syntax
mustBeNonNan(A)
Checks that no element of A is NaN. Returns nothing if the check passes and throws an error if not.
Description
mustBeNonNan is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeNonNan. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.
Only NaN is rejected, so Inf and -Inf pass. Use mustBeFinite to reject those too.
Input arguments
A- The value to check. Any array of the class the validator accepts.
Example
Passing and failing input
mustBeNonNan([1 Inf]);
disp('passed')
try
mustBeNonNan([1 NaN])
catch err
disp(err.message)
end
Output
passed
Value must not be NaN.