Documentation

mustBeReal

验证弗吉尼亚州lue is real or issue error

Syntax

mustBeReal(A)

Description

example

mustBeReal(A)issues an error ifAis not a real number. This function does not return a value.

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

Examples

collapse all

UsemustBeRealto validate that the input is a real number.

Validate that a calculation results in real numbers.

x = -2:2; z = x.^exp(-x.^2); mustBeReal(z)
Error using mustBeReal (line 13) values must be real.

The valuezis complex.

This class constrains the value ofProp1to real values.

classdefMyClasspropertiesProp1 {mustBeReal}endend

Create an object and assign a value to its property.

x = -2:0.1:2; obj = MyClass; obj.Prop1 = x.^exp(-x.^2);
Error setting 'Prop1' property of 'MyClass' class: values must be real.

When you assign a value to the property, MATLAB®callsmustBeRealwith the value being assigned to the property.mustBeRealissues an error because the value assigned toProp1is complex.

Input Arguments

collapse all

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

Other data types cause an error.

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

Extended Capabilities

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

Introduced in R2017a

Was this topic helpful?