Generating data points according to a distribution

9 views (last 30 days)
I've an array that is the distribution of a RV. Is there any way I can generate points which satisfies this distribution? Please note that it is not any standard distribution function.
Thanks

Answers (1)

Tom Lane
Tom Lane on 7 Jun 2012
1. If RV is a set of possible data points, you can randomly sample from it. One way to do that if you have the Statistics Toolbox is to use the datasample function.
2. If RV is a large random sample from the distribution but not the whole distribution, you could think of estimating the distribution using ksdensity and generating from that. An equivalent thing would be to randomly sample from RV and add some noise, perhaps using u*randn where u is your desired bandwidth and randn is the function that generates standard normal values.
3. Sounds like this is not true, but if RV were an inverse cdf function, you could generate random probability values using rand and invert them.
4. Sounds like this is not true, but if RV were a density function things are a little harder, but the slicesample function can generate correlated values from it, and the set of these values might be adequate for your purposes.
  2 Comments
Prabhu
Prabhu on 7 Jun 2012
Thanks Tom! Could you elaborate a bit more on the third option?
What do you mean by inverting probabilities?
Tom Lane
Tom Lane on 7 Jun 2012
The Statistics Toolbox has a function norminv for computing the inverse cdf of the normal distribution. You could run norminv(rand) to get a normal random value. It turns out that we also have normrnd for generating normal random numbers directly by a method we think is better. But if you only had norminv or some other inverse cdf, you could generate random numbers this way.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!