Vectorizing Simple Loops for Faster Execution Time in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter vijetha9
  • Start date Start date
  • Tags Tags
    Loops
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 2K views
vijetha9
Messages
2
Reaction score
0
Hie all

Can anyone please help me with this problem

I need to vectorize the following MATLAB code :
for c=1:3
h = randn(3,3) + j * randn(3,3);
z( :, :,c) = h;
end

Im basically trying to create a 3-D matrix - which has 3 , 2-D matrices (these matrices contain radomly generated complex numbers. The above code is working but i want to vectorize it for faster execution time.

Thanx
 
Last edited:
Physics news on Phys.org
Is there any problem with this:

Code:
h = randn(3,3,3) + j * randn(3,3,3);

EDIT: I missed that you used 'randn' as opposed to 'rand'... I think it will work either way...

-Kerry
 
Last edited: