Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

mustBeInteger

Validate that value is integer or issue error

Syntax

mustBeInteger(A)

Description

example

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:

Examples

collapse all

Validate that a calculation results in integer values.

A = randi(9)/randi(9);
mustBeInteger(A)
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
   properties
      Prop1 {mustBeInteger}
   end
end

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

Was this topic helpful?