Documentation

complex

Create complex array

Syntax

z = complex(a,b)
z = complex(x)

Description

example

z= complex(a,b)creates a complex output,z,从两个真正的输入,这样z = a + bi.

Thecomplexfunction provides a useful substitute for expressions, such asa + 1i*ba + 1j*b, when

  • aandbare notdoublesingle

  • bis all zeros

example

z= complex(x)returns the complex equivalent ofx, such thatisreal(z)returns logical0(false).

  • Ifxis real, thenzisx + 0i.

  • Ifxis complex, thenzis identical tox.

Examples

collapse all

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

z = complex(3,4)
z = 3.0000 + 4.0000i

Create a complexuint8vector from two realuint8vectors. The size ofz, 4-by-1, is the same as the size of the input arguments.

a = uint8([1;2;3;4]); b = uint8([2;2;7;7]); z = complex(a,b)
z =4x1 uint8 column vector1 + 2i 2 + 2i 3 + 7i 4 + 7i

Create a complex scalar with zero imaginary part.

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

Verify thatzis complex.

isreal(z)
ans =logical0

Input Arguments

collapse all

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

The size ofamust match the size ofb, unless one is a scalar. If eitherabis a scalar, MATLAB®扩大the scalar to match the size of the other input.

aandbmust be the same data type with the following exceptions:

  • singlecan combine withdouble.

  • scalardoublecan combine with an integer data type.

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

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

The size ofbmust match the size ofa, unless one is a scalar. If eitherabis a scalar, MATLAB expands the scalar to match the size of the other input.

aandbmust be the same data type with the following exceptions:

  • singlecan combine withdouble.

  • scalardoublecan combine with an integer data type.

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

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

collapse all

复杂的阵列,作为一个返回scalar, vector, matrix, or multidimensional array.

The size ofzis the same as the input arguments.

The following describes the data type ofz, whenaandbhave different data types.

  • If eitherabissingle, thenzissingle.

  • If eitherabis an integer data type, thenzis the same integer data type.

Tips

  • Ifbcontains only zeros, thenzis complex and the value of all its imaginary components is0. In contrast, the additiona + 0ireturns a strictly real result.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a

Was this topic helpful?