Generate N observations from a uniform distribution on [0,1] and compare it to a threshold
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ayman Alotaibi
am 10 Mär. 2018
Kommentiert: Ayman Alotaibi
am 10 Mär. 2018
We simulate this experiment by generating a logical array of
length N, with 1 (true) for "heads" and 0 (false) for "tails".
The problem is to generate the right number of 1s and 0s, so that
the percentage of 1s is p (60%). We shall do so in two ways.
N=1000; // number of coin tosses
p=0.6; // bias: percentage of 1s in the array
Method 1
Generate N observations from a uniform distribution on [0,1].
Threshold these observations at p. The resulting logical array
will have
1 if an observation was < p,
0 otherwise.
4 Kommentare
Akzeptierte Antwort
Roger Stafford
am 10 Mär. 2018
Here's another way. Let there be N1 trues and N0 falses.
x = [repmat(true,1,N1),repmat(false,1,N0)];
x = x(randperm(N1+N0));
4 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Measurements and Spatial Audio finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!