This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Validate that value is integer or issue error





mustBeInteger(A) issues an error if A does not contain integer values. mustBeInteger does not return a value.

This function accepts user-defined objects if the class of the object implements these methods:

This function ignores input arguments that are empty values. No error is thrown if the property value is empty.


collapse all

Validate that a calculation results in integer values.

A = randi(9)/randi(9);
Error using mustBeInteger (line 14)
Values must be integer.

If the result using random numbers is not an integer value, mustBeInteger issues an error.

Constrain the property values to be only integers.

classdef MyClass
      Prop1 {mustBeInteger}

Create an object and assign a value to its property.

obj = MyClass;
obj.Prop1 = randi(9)/randi(9);
Error setting 'Prop1' property of 'MyClass' class:
Value must be integer.

When you assign a value to the property, MATLAB® calls mustBeInteger with the value being assigned to the property. mustBeInteger issues an error because the value resulting from the division of these particular random integers did not result in an integer.

Input Arguments

collapse all

Value to validate, specified as a scalar or array of any of the following:

Other data types cause an error.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2017a