Generate N observations from a uniform distribution on [0,1] and compare it to a threshold
显示 更早的评论
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 个评论
James Tursa
2018-3-10
What have you done so far? What specific problems are you having with your code? Have you looked at the doc for the rand( ) function?
Ayman Alotaibi
2018-3-10
Ayman Alotaibi
2018-3-10
Ayman Alotaibi
2018-3-10
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Measurements and Spatial Audio 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!