how to create random numbers according to any distribution within a range
Afficher commentaires plus anciens
how to create random numbers according to any distribution within a range of values. Genertaed random number should fall within a range of values
Réponses (2)
Image Analyst
le 17 Mar 2016
1 vote
The first example, or any example, in the help of RAND does not say how you can get any distribution. It only talks about "uniform" distributions. For other built-in random distributions, you can see randn() or random(), which is in the Statistics and Machine Learning Toolbox.
A File Exchange submission, RANDRAW http://www.mathworks.com/matlabcentral/fileexchange/7309-randraw has over 50 built-in distributions you can choose from.
If you want your own custom shaped distribution (probability density function), you have to compute the cumulative distribution function from the probability density function and then invert that to get a function that you can then plug your uniformly distributed number into. This is called "inverse transform sampling" and here is the Wikipedia article on it: https://en.wikipedia.org/wiki/Inverse_transform_sampling
I've attached a script where I use that method to get random numbers drawn from the Rayleigh distribution.
Jos (10584)
le 17 Mar 2016
0 votes
First, carefully read the help of RAND, especially the first example in it.
The next step is to define your distribution more precisely.
Catégories
En savoir plus sur Random Number Generation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!