mustBeNumeric
Checks that a value is a numeric array.
Category: Programming > Functions
Syntax
mustBeNumeric(A)
Checks that A is of a numeric class. Returns nothing if the check passes and throws an error if not.
Description
mustBeNumeric is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeNumeric. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.
Every integer and floating-point class counts as numeric. Logicals and characters do not; use mustBeNumericOrLogical to accept logicals.
Input arguments
A- The value to check. Any array of the class the validator accepts.
Example
Passing and failing input
mustBeNumeric(int8(4));
disp('passed')
try
mustBeNumeric('abc')
catch err
disp(err.message)
end
Output
passed
Value must be numeric.