complex

Returns a complex number composed of real elements.

Syntax

complex(x)

complex(r, im)

Inputs

x
A real number.
Type: double | integer | logical | struct | cell
Dimension: scalar | vector | matrix
r
Real part of complex number.
Type: double | integer | logical | struct | cell
Dimension: scalar | vector | matrix
im
Imaginary part of complex number.
Type: double | integer | logical | struct | cell
Dimension: scalar | vector | matrix

Outputs

R
Complex number created from r and im.

Examples

Simple example for the usage of complex:

complex(1,8.2)
ans = [ 1 + 8.2i]

Single input example for complex. By calling iscomplex on ans, one can see that x was coverted to a complex from a real number:

complex(4)
ans = 4