Info
此问题已关闭。 请重新打开它进行编辑或回答。
How do I find the probability that 0 would be selected if a random number was selected?
1 次查看(过去 30 天)
显示 更早的评论
d = [1, 0.5, 0.01, 0.5, 0, 1, 2, 15.31, 33, 12, 3, 7, 2, 15, 38, 0, ...
2.5, 0, 0.4, 17.8, 0.5, 10.6, 0, 0.1, 11, 12, 1, 0.8, 0, 7, 10, ...
0, 10.1, 4.14, 0.5, 14.7, 0, 0, 0, 0, 0.1, 0. 37, 3.1, 25, 0, 1, ...
1.4, 7.5, 17.9, 30, 0, 0, 0, 14.2, 30, 23.7, 0, 0, 0, 7.7, 3.4, 0, ...
0, 0, 0, 0, 0, 0, 0.5, 0, 11, 0, 10, 0, 0, 70, 0, 15, 3.5, 9];
0 个评论
回答(2 个)
Sarah Crimi
2019-2-7
d = [1, 0.5, 0.01, 0.5, 0, 1, 2, 15.31, 33, 12, 3, 7, 2, 15, 38, 0, ...
2.5, 0, 0.4, 17.8, 0.5, 10.6, 0, 0.1, 11, 12, 1, 0.8, 0, 7, 10, ...
0, 10.1, 4.14, 0.5, 14.7, 0, 0, 0, 0, 0.1, 0. 37, 3.1, 25, 0, 1, ...
1.4, 7.5, 17.9, 30, 0, 0, 0, 14.2, 30, 23.7, 0, 0, 0, 7.7, 3.4, 0, ...
0, 0, 0, 0, 0, 0, 0.5, 0, 11, 0, 10, 0, 0, 70, 0, 15, 3.5, 9];
%create a counter to count the number of zeros
counter=0;
%Create a loop to add 1 each time there is another 0.
for i=1:length(d)
if(d(i)==0)
counter = counter+1;
end
end
Kevin Phung
2019-2-7
编辑:Kevin Phung
2019-2-7
Just do:
d = [1, 0.5, 0.01, 0.5, 0, 1, 2, 15.31, 33, 12, 3, 7, 2, 15, 38, 0, ...
2.5, 0, 0.4, 17.8, 0.5, 10.6, 0, 0.1, 11, 12, 1, 0.8, 0, 7, 10, ...
0, 10.1, 4.14, 0.5, 14.7, 0, 0, 0, 0, 0.1, 0. 37, 3.1, 25, 0, 1, ...
1.4, 7.5, 17.9, 30, 0, 0, 0, 14.2, 30, 23.7, 0, 0, 0, 7.7, 3.4, 0, ...
0, 0, 0, 0, 0, 0, 0.5, 0, 11, 0, 10, 0, 0, 70, 0, 15, 3.5, 9];
Probability = sum(d==0)/ numel(d);
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!