mustBeInteger

Checks that every element is a whole number.

Category: Programming > Functions

Syntax

mustBeInteger(A)

Checks that every element of A has an integer value. Returns nothing if the check passes and throws an error if not.

Description

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

The test is about the value, not the class: 3.0 of class double passes, and so do integer-class arrays and logicals. A value such as 1.5 fails.

Input arguments

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

Example

Passing and failing input

mustBeInteger([1 2 3]);
disp('passed')
try
    mustBeInteger(1.5)
catch err
    disp(err.message)
end
Output
passed
Value must be integer.

See also

mustBeNumeric mustBeFinite mustBePositive round