| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
TF = isreal(A)
TF = isreal(A) returns logical 1 (true) if A does not have an imaginary part. It returns logical 0 (false) otherwise. If A has a stored imaginary part of value 0, isreal(A) returns logical 0 (false).
Note For logical and char data classes, isreal always returns true. For numeric data types, if A does not have an imaginary part isreal returns true; if A does have an imaginary part isreal returns false. For cell, struct, function_handle, and object data types, isreal always returns false. |
~isreal(x) returns true for arrays that have at least one element with an imaginary component. The value of that component can be 0.
If A is real, complex(A) returns a complex number whose imaginary component is 0, and isreal(complex(A)) returns false. In contrast, the addition A + 0i returns the real value A, and isreal(A + 0i) returns true.
If B is real and A = complex(B), then A is a complex matrix and isreal(A) returns false, while A(m:n) returns a real matrix and isreal(A(m:n)) returns true.
Because MATLAB software 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.
If a computation results in a zero-value imaginary component, isreal returns true.
x=3+4i;
y=5-4i;
isreal(x+y)
ans =
1These examples use isreal to detect the presence or absence of imaginary numbers in an array. Let
x = magic(3); y = complex(x);
isreal(x) returns true because no element of x has an imaginary component.
isreal(x)
ans =
1isreal(y) returns false, because every element of x has an imaginary component, even though the value of the imaginary components is 0.
isreal(y)
ans =
0This expression detects strictly real arrays, i.e., elements with 0-valued imaginary components are treated as real.
~any(imag(y(:)))
ans =
1Given the following cell array,
C{1} = pi; % double
C{2} = 'John Doe'; % char array
C{3} = 2 + 4i; % complex double
C{4} = ispc; % logical
C{5} = magic(3); % double array
C{6} = complex(5,0) % complex double
C =
[3.1416] 'John Doe' [2.0000+ 4.0000i] [1] [3x3 double] [5]isreal shows that all but C{1,3} and C{1,6} are real arrays.
for k = 1:6
x(k) = isreal(C{k});
end
x
x =
1 1 0 1 1 0complex, isnumeric, isnan, isprime, isfinite, isinf, isa, is*
![]() | isprop | isscalar | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |