Generate samples from a normal distribution
显示 更早的评论
Hello,
I have a Gaussian mixture distribution which looks as attached. I now want to sample and generate 1000 samples from this and plot their histogram. I tried using randi function but it does not work. Please let me know how to do this.
y = randi(my_pdf,100); %%my_pdf is my distribution
Thanks!
5 个评论
Walter Roberson
2016-11-25
Is that a continuous function or a discrete function?
Torsten
2016-11-25
Could you explain the graphic in gmm.jpg ?
It's not a distribution generated with normpdf, not even a distribution ...
So what is it ?
Best wishes
Torsten.
Image Analyst
2016-11-25
Please supply the hw function so we can run your code.
回答(3 个)
Image Analyst
2016-11-25
1 个投票
If you have that function already, then use inverse transform sampling: https://en.wikipedia.org/wiki/Inverse_transform_sampling. In short, compute the CDF of your function and use rand() to pick a value.
I attach an example of how I used it for the Rayleigh distribution.
CarrotCakeIsYum
2016-11-25
randi will generate rando integers.
To generate a random sample from a vector, use randsample. see:
help randsample
I'd imagine you'd want:
y = randsample(my_pdf,100);
To plot a histogram use the 'hist' command.
2 个评论
Kash022
2016-11-25
CarrotCakeIsYum
2016-11-25
Sorry I don't follow... your population will only have one mean!
For the JPEG you've posted, the mean will be at 7.5 (since it is a symmetrical distribution).
Image Analyst
2016-11-25
0 个投票
Maybe use randn() to get a list of a few million numbers taken from those 13 distributions (call randn thirteen times), then pick one of the values at random.
类别
在 帮助中心 和 File Exchange 中查找有关 Normal Distribution 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!