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