A complex number can be created in MATLAB using the COMPLEX function. To initialize a complex number with zero as the real part and non-zero imaginary part, enter the following at the MATLAB command prompt
a = zeros(1,100);
x = complex(a,0);
To verify that the above command actually creates a 100-by-1 complex array, enter the following at the MATLAB command prompt
If you were to create the complex arrary with the above code and then assign a pure real number to one part of x or perform an arithmetic operation with a real number, MATLAB will de-allocate the complex part of the variable x . Type the following commands to observe this behavior:
When a real number, 1.0 was added to x, MATLAB de-allocates the complex part of the variable x and creates a 100-by-1 real double array. To keep the complex part, wrap COMPLEX around the expression.