# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

# isreal

Determine whether array is real

tf = isreal(A)

## Description

example

tf = isreal(A) returns logical 1 (true) when A does not have an imaginary part. Otherwise, it returns logical 0 (false).

If A has a stored imaginary part with value 0, then isreal(A) returns logical 0 (false).

## Examples

collapse all

Define a 3-by-4 matrix, A.

A = [7 3+4i 2 5i;...
2i 1+3i 12 345;...
52 108 78 3];

Determine whether the array is real.

tf = isreal(A)
tf = logical
0

Since A contains complex elements, isreal returns false.

Use the complex function to create a scalar, A, with zero-valued imaginary part.

A = complex(12)
A =
12.0000 + 0.0000i

Determine whether A is real.

tf = isreal(A)
tf = logical
0

A is not real because it has an imaginary part, even though the value of the imaginary part is 0.

Determine whether A contains any elements with zero-valued imaginary part.

~any(imag(A))
ans = logical
1

A contains elements with zero-valued imaginary part.

Define two complex scalars, x and y.

x=3+4i;
y=5-4i;

Determine whether the addition of two complex scalars, x and y, is real.

A = x+y
A = 8

MATLAB® drops the zero imaginary part.

isreal(A)
ans = logical
1

A is real since it does not have an imaginary part.

Create a cell array.

C{1,1} = pi;                 % double
C{2,1} = 'John Doe';         % char array
C{3,1} = 2 + 4i;             % complex double
C{4,1} = ispc;               % logical
C{5,1} = magic(3);           % double array
C{6,1} = complex(5,0)        % complex double
C = 6x1 cell array
{[          3.1416]}
{'John Doe'        }
{[2.0000 + 4.0000i]}
{[               0]}
{3x3 double        }
{[5.0000 + 0.0000i]}

C is a 1-by-6 cell array.

Loop over the elements of a cell array to distinguish between real and complex elements.

for k = 1:6
x(k,1) = isreal(C{k,1});
end

x
x = 6x1 logical array
1
1
0
1
1
0

All but C{3,1} and C{6,1} are real arrays.

## Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array.

• 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 logical and char data types, isreal always returns true.

• For table, cell, struct, datetime, function_handle, and object data types, isreal always returns false.

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

## Tips

• isreal(complex(A)) always returns false, even when the imaginary part is all zeros.

• ~isreal(x) detects arrays that have an imaginary part, even if it is all zeros.