Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Vectorization of simple loops

  1. Mar 26, 2009 #1
    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: Mar 26, 2009
  2. jcsd
  3. Mar 26, 2009 #2
    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
  4. Mar 30, 2009 #3
    thanks.. it works....
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Vectorization of simple loops
Loading...