Documentation Center

  • Trials
  • Product Updates

complex

Create complex array

Syntax

Description

example

z = complex(a,b) creates a complex output, z, from two real inputs, such that z = a + bi.

The complex function provides a useful substitute for expressions, such as a + 1i*b or a + 1j*b, when

  • a and b are not double or single

  • b is all zeros

example

z = complex(x) returns the complex equivalent of x, such that isreal(z) returns logical 0 (false).

  • If x is real, then z is x + 0i.

  • If x is complex, then z is identical to x.

Examples

expand all

Complex Scalar from Two Real Scalars

Use the complex function to create the complex scalar, 3 + 4i.

z = complex(3,4)
z =

   3.0000 + 4.0000i

Complex Vector from Two Complex Vectors

Create a complex uint8 vector from two real uint8 vectors.

a = uint8([1;2;3;4]);
b = uint8([2;2;7;7]);

z = complex(a,b)
z =

    1 +    2i
    2 +    2i
    3 +    7i
    4 +    7i

The size of z, 4-by-1, is the same as the size of the input arguments.

Complex Scalar from One Real Scalar

Create a complex scalar with zero imaginary part.

z = complex(12)
z =

  12.0000 + 0.0000i

Verify that z is complex.

isreal(z)
ans =

     0

Input Arguments

expand all

a — Real componentscalar | vector | matrix | multidimensional array

Real component, specified as a scalar, vector, matrix, or multidimensional array.

The size of a must match the size of b, unless one is a scalar. If either a or b is a scalar, MATLAB® expands the scalar to match the size of the other input.

a and b must be the same data type with the following exceptions:

  • single can combine with double.

  • scalar double can combine with an integer data type.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

b — Imaginary componentscalar | vector | matrix | multidimensional array

Imaginary component, specified as a scalar, vector, matrix, or multidimensional array.

The size of b must match the size of a, unless one is a scalar. If either a or b is a scalar, MATLAB expands the scalar to match the size of the other input.

a and b must be the same data type with the following exceptions:

  • single can combine with double.

  • scalar double can combine with an integer data type.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

x — Input arrayscalar | vector | matrix | multidimensional array

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

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

Output Arguments

expand all

z — Complex arrayscalar | vector | matrix | multidimensional array

Complex array, returned as a scalar, vector, matrix, or multidimensional array.

The size of z is the same as the input arguments.

The following describes the data type of z, when a and b have different data types.

  • If either a or b is single, then z is single.

  • If either a or b is an integer data type, then z is the same integer data type.

More About

expand all

Tips

  • If b contains only zeros, then z is complex and the value of all its imaginary components is 0. In contrast, the addition a + 0i returns a strictly real result.

See Also

| | | | | | |

Was this topic helpful?