Random numbers from CDF
    4 views (last 30 days)
  
       Show older comments
    
    Hannah Taylor
 on 29 Oct 2020
  
    
    
    
    
    Edited: Michael Croucher
      
 on 29 Oct 2020
            Hello,
I have a probability distribution with a specified sigma and mu, I've converted this into a pdf and cdf but I'm struggling to work out how to extract random numbers from this cdf?  Could anyone point me in the direction of any advice / examples - thanks!
Here's what I have so far:
rng('shuffle') 
pd = makedist('normal',"mu",1.124,"sigma",0.903);
x=[0:0.001:5]; %I need my random numbers to be between 0 and 5.
y=pdf(pd,x);
c=cdf(pd,x);
d=scatter(x,c) %sense check to see if this looks as expected!
0 Comments
Accepted Answer
  Michael Croucher
      
 on 29 Oct 2020
        
      Edited: Michael Croucher
      
 on 29 Oct 2020
  
      You can pass your pd to the random function.  Does this do what you want?  To get a 100000 by 1 vector of random numbers from your distribution:
random_draws = random(pd,100000,1)
0 Comments
More Answers (0)
See Also
Categories
				Find more on Random Number Generation in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!