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.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.