How to sample from a distribution?

How do you use randsample (or maybe something else?) to sample from a distribution? Can you define a non-standard distribution as long as you have the formula for the pdf?

 Risposta accettata

Star Strider
Star Strider il 20 Gen 2023

0 voti

How do you use randsample (or maybe something else?) to sample from a distribution?
The random function can be used with known distributions.
Can you define a non-standard distribution as long as you have the formula for the pdf?
Yes. See Nonparametric and Empirical Probability Distributions for an extensive discussion. The ecdf function can be used to define an empirical distibution. (Getting random numbers from it would likely require inverting its pdf first, and that could be something of a challenge, depending on the distribution.)
.

4 Commenti

Thank you! Perhaps I should've combined my two questions: how can you sample from a non-standard distribution? The random function is used with known distributions, and although now I know ecdf lets me define an empirical distribution, I still don't know how to get random numbers from it (or another method).
My pleasure!
I’m not certain either. As I mentioned, that may require inverting it, and while that can likely be done with interp1 easily enough, not efficiently. It likely depends on the distribution itself.
Thank you! I'll ask a similar question separately, since I think it pertains to this question. Maybe you can help me with it.
As always, my pleasure!
I will do my best!

Accedi per commentare.

Più risposte (0)

Prodotti

Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by