dice probability game with graph of results

4 ビュー (過去 30 日間)
Brian
Brian 2013 年 6 月 15 日
I have to create a simulation of a player throwing two dice (1:6) then summing the total of the two throws eg 3+4 gives 7. I have to count the number that gives a total of 6. I did that part fine, but I need a graph of the number of throws vs the number of throws which resulted in a 6 with a line showing the theoretical value, which the throws should converge to.
This is what I did:
r = randi([1 6],1000,1);
d = randi ([1 6],1000,1);
e = r+d
out = e(6)
rangesLowValue = 6;
rangesHighValue = 6;
Numberof6s = sum(e(:) >= rangesLowValue & e(:)<=rangesHighValue)
x=1:1000
plot(Numberof6s,x) %Don't know what to do here.
Thanks for any help.

採用された回答

the cyclist
the cyclist 2013 年 6 月 15 日
編集済み: the cyclist 2013 年 6 月 15 日
Try the cumsum() function instead of the sum() function, and I think you get what you intended.
You probably also want
plot(x,Numberof6s)
rather than
plot(Numberof6s,x)
  1 件のコメント
Brian
Brian 2013 年 6 月 15 日
thanks man!! it worked

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumber games についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by