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!