Fast conversion of 2 matrices to 1 complex matrix
Hi,
After reading my data from an external binary file, I have a 3 dimensional array representing one complex matrix, like this:
A(1,:,:) = rand(10); % real part
A(2,:,:) = rand(10); % imaginary part
I need to convert that into a complex matrix, e.g.
A = complex(A(1,:,:), A(2,:,:));
But this is rather slow. As far as I have been able to find out, Matlab stores complex matrices internally as two matrices, one for the real and one for the imaginary part. This is about the same as my original 3-dimensional matrix — and should be quite fast! My assumption therefore is that Matlab uses a temporary variable which of course needs to be allocated, resulting in slow code.
Is it possible to make Matlab do this conversion without allocating more memory? Maybe just setting the ‘complex’ attribute to A… It might be possible using mex files, but I never used them before, and I would prefer a ‘pure’ Matlab solution.
Any comments, hints or keywords I can google for are welcome!
Regards ArgonHi,
After reading my data from an external binary file, I have a 3 dimensional array representing one complex matrix, like this:
A(1,:,:) = rand(10); % real part
A(2,:,:) = rand(10); % imaginary part
I need to convert that into a complex matrix, e.g.
A = complex(A(1,:,:), A(2,:,:));
But this is rather slow. As far as I have been able to find out, Matlab stores complex matrices internally as two matrices, one for the real and one for the imaginary part. This is about the same as my original 3-dimensional matrix — and should be quite fast! My assumption therefore is that Matlab uses a temporary variable which of course needs to be allocated, resulting in slow code.
Is it possible to make Matlab do this conversion without allocating more memory? Maybe just setting the ‘complex’ attribute to A… It might be possible using mex files, but I never used them before, and I would prefer a ‘pure’ Matlab solution.
Any comments, hints or keywords I can google for are welcome!
Regards Argon Hi,
After reading my data from an external binary file, I have a 3 dimensional array representing one complex matrix, like this:
A(1,:,:) = rand(10); % real part
A(2,:,:) = rand(10); % imaginary part
I need to convert that into a complex matrix, e.g.
A = complex(A(1,:,:), A(2,:,:));
But this is rather slow. As far as I have been able to find out, Matlab stores complex matrices internally as two matrices, one for the real and one for the imaginary part. This is about the same as my original 3-dimensional matrix — and should be quite fast! My assumption therefore is that Matlab uses a temporary variable which of course needs to be allocated, resulting in slow code.
Is it possible to make Matlab do this conversion without allocating more memory? Maybe just setting the ‘complex’ attribute to A… It might be possible using mex files, but I never used them before, and I would prefer a ‘pure’ Matlab solution.
Any comments, hints or keywords I can google for are welcome!
Regards Argon complex, memory allocation MATLAB Answers — New Questions