complex - Create complex array - MATLAB (original) (raw)

Syntax

Description

[z](#bt4jyjw-1-z) = complex([a](#bt4jyjw-1-a),[b](#bt4jyjw-1-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

example

[z](#bt4jyjw-1-z) = complex([x](#bt4jyjw-1-x)) returns the complex equivalent of x, such that isreal(z) returns logical 0 (false).

example

Examples

collapse all

Complex Scalar from Two Real Scalars

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

Complex Vector from Two Real Vectors

Create a complex uint8 vector from two real uint8 vectors. The size of z, 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 vector

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

Complex Scalar from One Real Scalar

Create a complex scalar with zero imaginary part.

Verify that z is complex.

Input Arguments

collapse all

a — Real component

scalar | 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 can have different data types. However, if either a or b is an integer data type, then the other input must have the same integer type or be a full (not sparse) scalar double.

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

b — Imaginary component

scalar | 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 can have different data types. However, if either a or b is an integer data type, then the other input must have the same integer type or be a full (not sparse) scalar double.

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

x — Input array

scalar | 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 | logical
Complex Number Support: Yes

Output Arguments

collapse all

z — Complex array

scalar | 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 andb have different data types.

Additionally, z is only sparse when both input arguments a and b are sparse.

Tips

Extended Capabilities

Tall Arrays

Calculate with arrays that have more rows than fit in memory.

Thecomplex function fully supports tall arrays. For more information, see Tall Arrays.

C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation

Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

HDL Code Generation

Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

Thread-Based Environment

Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

GPU Arrays

Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.

The complex function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Distributed Arrays

Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.

This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).

Version History

Introduced before R2006a