mustBeFloat
Checks that a value is of class double or single.
Category: Programming > Functions
Syntax
mustBeFloat(A)
Checks that A is a floating-point array. Returns nothing if the check passes and throws an error if not.
Description
mustBeFloat is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeFloat. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.
Only double and single arrays pass. Integer types, logicals and characters fail even though they can be converted to floating point.
Input arguments
A- The value to check. Any array of the class the validator accepts.
Example
Passing and failing input
mustBeFloat(single(2.5));
disp('passed')
try
mustBeFloat(int8(1))
catch err
disp(err.message)
end
Output
passed
Value must be a floating-point array.