mustBeNumericOrLogical

Checks that a value is numeric or logical.

Category: Programming > Functions

Syntax

mustBeNumericOrLogical(A)

Checks that A is numeric or logical. Returns nothing if the check passes and throws an error if not.

Description

mustBeNumericOrLogical is a validator: it inspects its input and either returns silently or raises an error with the identifier MATLAB:validators:mustBeNumericOrLogical. The error message states the requirement that was violated, so the caller sees what was expected rather than a generic failure.

This is the usual check for data that will be used in arithmetic or as a mask. Characters, strings and cell arrays fail.

Input arguments

A
The value to check. Any array of the class the validator accepts.

Example

Passing and failing input

mustBeNumericOrLogical([true false]);
disp('passed')
try
    mustBeNumericOrLogical('a')
catch err
    disp(err.message)
end
Output
passed
Value must be numeric or logical.

See also

mustBeNumeric isnumeric islogical mustBeA