# Vectorization of simple loops

1. Mar 26, 2009

### vijetha9

Hie all

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: Mar 26, 2009
2. Mar 26, 2009

### KLoux

Is there any problem with this:

Code (Text):

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: Mar 26, 2009
3. Mar 30, 2009

### vijetha9

thanks.. it works....