mustBeUnderlyingType
Checks that an array has the given underlying class.
Category: Programming > Functions
Syntax
mustBeUnderlyingType(A, typename)
Checks that the underlying class of A equals typename. Returns nothing if the check passes and throws an error if not.
Description
mustBeUnderlyingType is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeUnderlyingType. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.
Unlike mustBeA, only the exact underlying class counts, and inheritance is not considered. For ordinary built-in arrays the underlying class is just class(A).
Input arguments
A- The value to check. Any array of the class the validator accepts.
typename- Class name as text. Several names may be given in a cell array.
Example
Passing and failing input
mustBeUnderlyingType(int8(1), 'int8');
disp('passed')
try
mustBeUnderlyingType(int8(1), 'double')
catch err
disp(err.message)
end
Output
passed
Value must have underlying type 'double'.