Pick a number from an array with a certain probability
Show older comments
Hi!
I have an array from 1 to 150 [1 2 3 ...]
and the corresponding probability [0.001 0.003 0.002 ...]
Now I'd like to pick a random number from the first array with taking into account the respective probability.
Has anyone an idea how to proceed?
Thanks!
Accepted Answer
More Answers (1)
Image Analyst
on 25 May 2020
0 votes
Is this homework? Sounds like it. See Wikipedia: https://en.wikipedia.org/wiki/Inverse_transform_sampling
Hint: use cumsum(probabililtyVector) and see if a random number is less than the cdf.
Categories
Find more on Creating and Concatenating Matrices 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!