Main Content

complex

Construct complex fi object from real and imaginary parts

Description

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

When b is all zero, c is complex with an all-zero imaginary part. This is in contrast to the addition of a + 0i, which returns a strictly real result.

example

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

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

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

example

Examples

collapse all

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

a = fi(3,1,16,12);
b = fi(4,0,8);
c = complex(a,b)
c = 

   3.0000 + 4.0000i

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 12

The output, c, has the same numerictype and fimath properties as the input fi object, a.

Create a complex fi vector with a zero imaginary part.

x = fi([1;2;3;4]);
c = complex(x)
c = 

   1.0000 + 0.0000i
   2.0000 + 0.0000i
   3.0000 + 0.0000i
   4.0000 + 0.0000i

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 12

Verify that c is complex.

isreal(c)
ans =

  logical

   0

Input Arguments

collapse all

Real component, specified as a fi 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.

Data Types: fi

Imaginary component, specified as a fi 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.

Data Types: fi

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

Data Types: fi

Output Arguments

collapse all

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

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

The output fi object, c, has the same numerictype and fimath properties as the input fi object, a.

Extended Capabilities

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

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

Version History

Introduced before R2006a

See Also

| |