Difference between revisions of "Likelihood"

From Sean_Carver
Jump to: navigation, search
Line 25: Line 25:
 
   end
 
   end
  
Note however there is really two issues with the second method: first, we could have avoided the loop, and second, the we successively building a larger and larger array without first initializing it.  Now that B is defined, repeating the second set of command will go much faster.  Note semicolons suppress a command's insistence on displaying the result on the screen.  Try it without the semicolon:
+
Note however there is really two issues with the second method: first, we could have avoided the loop, and second, the we successively built a larger and larger array without first initializing it.  Now that B is defined, repeating the second set of command will go much faster, but still not as fast as avoiding the loop.   
 +
 
 +
Note semicolons suppress a command's insistence on displaying the result on the screen.  Try it without the semicolon:
  
 
   A = rand(10000,1)
 
   A = rand(10000,1)

Revision as of 15:21, 23 January 2009

Random Numbers in MATLAB

Start MATLAB and type the following into the MATLAB prompt

 rand

This produces a random number. Repeat several times. Continue typing the material in boxes into the MATLAB prompt.

 help rand

Returns help for the rand command. We'll discuss this help file. Try

 rand(3)
 rand(3,2)
 rand(3,2,2)

These commands allow you to create arrays of random numbers without loops. Compare

 A = rand(10000,1);

With

 for i = 1:10000
 B(i,1) = rand;
 end

Note however there is really two issues with the second method: first, we could have avoided the loop, and second, the we successively built a larger and larger array without first initializing it. Now that B is defined, repeating the second set of command will go much faster, but still not as fast as avoiding the loop.

Note semicolons suppress a command's insistence on displaying the result on the screen. Try it without the semicolon:

 A = rand(10000,1)