MATLAB Function Reference Previous page   Next Page

Determine if all array elements are real numbers



tf = isreal(A) returns logical 0 (false) if any element of array A has an imaginary component, even if the value of that component is 0. It returns logical 1 (true) otherwise.

~isreal(x) returns true for arrays that have at least one element with an imaginary component. The value of that component can be 0.

Because MATLAB supports complex arithmetic, certain of its functions can introduce significant imaginary components during the course of calculations that appear to be limited to real numbers. Thus, you should use isreal with discretion.


Example 1. These examples use isreal to detect the presence or absence of imaginary numbers in an array. Let

isreal(x) returns true because no element of x has an imaginary component.

isreal(y) returns false, because every element of x has an imaginary component, even though the value of the imaginary components is 0.

This expression detects strictly real arrays, i.e., elements with 0-valued imaginary components are treated as real.

Example 2. Given the following cell array,

isreal shows that all but C{1,3} and C{1,6} are real arrays.

See Also

complex, isnumeric, isnan, isprime, isfinite, isinf, isa, is*

Previous page  isprop isscalar Next page

© 1994-2005 The MathWorks, Inc.