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 numeric or issue error





mustBeNumeric(A) issues an error if A is not numeric. This function does not return a value.

mustBeNumeric accepts user-defined objects if the class of the object implements this method:

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


collapse all

Validate that the result of an operation is numeric.

mustBeNumeric(5 < 10)
Error using mustBeNumeric (line 10)
Values must be numeric.

The relational operator for less than returns a logical value.

This class constrains the value of Prop1 to numeric values.

classdef MyClass
      Prop1 {mustBeNumeric}

Create an object and assign a value to its property.

obj = MyClass;
obj.Prop1 = isprime(29);
Error setting 'Prop1' property of 'MyClass' class:
Values must be numeric.

When you assign a value to the property, MATLAB® calls mustBeNumeric with the value being assigned to the property. mustBeNumeric issues an error because the value assigned to Prop1 is a logical.

Input Arguments

collapse all

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

  • Any MATLAB numeric class

  • MATLAB classes that implement isnumeric

Other data types cause an error.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
Complex Number Support: Yes

Extended Capabilities

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

Introduced in R2017a