From: Marios Karaoulis on
How can i pre-allocate a complex matrix with zeros everywhere?
If i use this command
x=zeros(5,6)+j*zeros(5,6), I end up with a real matrix

if I use this
x=zeros(5,6)+j*ones(5,6);
then I do not have zeros in the imaginary part.
Any ideas?
From: dpb on
Marios Karaoulis wrote:
> How can i pre-allocate a complex matrix with zeros everywhere?
> If i use this command
> x=zeros(5,6)+j*zeros(5,6), I end up with a real matrix
>
> if I use this
> x=zeros(5,6)+j*ones(5,6);
> then I do not have zeros in the imaginary part.
> Any ideas?

Just use

x=zeros(5,6)

When you reference an element w/ a nonzero imaginary component, ML will
automagically handle it...

Example...

>> z=zeros(3,1);
>> z(2) = i
z =
0
0 + 1.0000i
0
>>

--

From: Wayne King on
Marios Karaoulis <marios.karaoulis(a)gmail.com> wrote in message <0e877227-c134-4d60-ba37-cb631943f345(a)a16g2000prg.googlegroups.com>...
> How can i pre-allocate a complex matrix with zeros everywhere?
> If i use this command
> x=zeros(5,6)+j*zeros(5,6), I end up with a real matrix
>
> if I use this
> x=zeros(5,6)+j*ones(5,6);
> then I do not have zeros in the imaginary part.
> Any ideas?

Hi Marios, If you want the Attributes field to show up as complex, you can do

x = complex(zeros(5,6), zeros(5,6));

but I'm not sure what difference it makes. How does it matter that the entries of the matrix don't display as 0+j0?

You can still do things like:

x=zeros(5,6);
y = randn(5,6)+1j*randn(5,6);
x+y
% the sum is defined


Wayne
From: Marios Karaoulis on
I think, that matlab automatically checks if there is reason for a
matrix to be complex or not (so reduce the memory size).
This way it is slower if you preallocate a complex matrix as real, and
then during execution you change an element so it can be compelx. Then
matlab re-preallocate another matrix so it can handle complex numbers.

From: Bruno Luong on
Marios Karaoulis <marios.karaoulis(a)gmail.com> wrote in message <0e877227-c134-4d60-ba37-cb631943f345(a)a16g2000prg.googlegroups.com>...
> How can i pre-allocate a complex matrix with zeros everywhere?
> If i use this command
> x=zeros(5,6)+j*zeros(5,6), I end up with a real matrix
>
> if I use this
> x=zeros(5,6)+j*ones(5,6);
> then I do not have zeros in the imaginary part.
> Any ideas?

There is no need to preallocate the imaginary part: as soon as the first true complex element is assigned to your array, the whole memory block (same size as the real part) reserved for imaginary part will be allocated. All you need is allocated with zeros(), don't bother with the rest.

Bruno