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 nonNaN





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

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


collapse all

Use mustBeNonNan to validate that no array elements are NaN.

A = 0./[-2 -1 0 1 2];
Error using mustBeNonNan (line 13)
Value must not be NaN.

Division of 0 by 0 is equal to NaN so the array value contains one element that is NaN, which causes an error.

This class constrains the value of Prop1 to nonNaN values.

classdef MyClass
      Prop1 {mustBeNonNan}

Create an object and assign a value to Prop1.

obj = MyClass;
obj.Prop1 = 0./[-2 -1 0 1 2];
Error setting property 'Prop1' of class 'MyClass':
Value must not be NaN.

When you assign a value to the property, MATLAB® calls mustBeNonNan with the value being assigned to the property. mustBeNonNan issues an error because division of 0 by 0 is NaN.

Input Arguments

collapse all

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

  • All MATLAB numeric classes and logical.

  • MATLAB user-defined classes that implement isnan

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

Extended Capabilities

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

Introduced in R2017a