How to generate realisations from two sets

조회 수: 9 (최근 30일)
mohamed Faraj
mohamed Faraj 2019년 8월 28일
편집: the cyclist 2019년 8월 28일
I have two sets,e.g., S1={1,2,3,4} and S2={1,2,3,4,5}. I want to pick up 2 numbers randomly from S1 and 3 numbers from S2. Note that the order of the 2 or 3 picked numbers is not important. Theoretically, the probability that a number will appear in both sets is 2/4*3/5=6/20 (Am I correct?). I want to prove this using matlab by generating a large number of realizations and check the distribution.

답변 (1개)

the cyclist
the cyclist 2019년 8월 28일
편집: the cyclist 2019년 8월 28일
L1 = length(S1);
N1 = 2;
S1(randperm(L1,N1))
will choose N1 numbers (in this case, 2) from S1. You can choose similarly from S2.
Regarding your probability estimate ...
You cannot say in general that the probability of appearing in both sets is 6/20. What if S1 and S2 have no numbers in common?

Community Treasure Hunt

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

Start Hunting!

Translated by