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





mustBeFinite(A) issues an error if A is not finite. A value is finite if it is not NaN or Inf. This function does not return a value.

This function accepts user-defined objects if the class of the object implements the following method:

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


collapse all

Use mustBeFinite to validate that no array elements are NaN or Inf.

d = 0:9;
A = 1./d;
Error using mustBeFinite (line 13)
Value must be finite.

The division by d resulted in one element becoming Inf, which causes an error.

This class constrains the value of Prop1 to finite values.

classdef MyClass
      Prop1 {mustBeFinite}

Create an object and assign a value to its property.

d = 0:9;
obj = MyClass;
obj.Prop1 = 1./d;
Error setting property 'Prop1' of class 'MyClass':
Value must be finite.

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

Input Arguments

collapse all

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

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