Simulation of custom probability distribution in Matlab

803 Views Asked by At

I'm trying to simulate the following distribution:

 a   |  0   |  1   |  7   |  11  |  13 
-----------------------------------------
p(a) | 0.34 | 0.02 | 0.24 | 0.29 | 0.11

I already simulated a similar problem: four type of balls with chances of 0.3, 0.1, 0.4 and 0.2. I created a vector F = [0 0.3 0.4 0.8 1] and used repmat to grow it by 1000 rows. Then I compared it with a columnvector of 1000 random numbers grown with 5 columns using the same repmat approach. I compared those two, calculated the sumvector of the matrix, and calculated the difference to get the frequences (e.g. [301 117 386 196]).

But with the current distribution I don't know how to create the initial matrix F and whether I can use the same approach I used before at all.

I need the answer to be "vectorised", so no (for, while or if) loops.

This question on Stackoverflow

1

There are 1 best solutions below

2
On BEST ANSWER

Wouldn't this be what you're looking for?

y = randsample([0 1 7 11 13],100,true,[0.34 0.02 0.24 0.29 0.11])

For larger sample sizes, just change 100 to whatever you want.