How would I create a plot showing each event on the X axis and P(X), the probability of each event, on the Y axis?

4 ビュー (過去 30 日間)
Given, a two six-sided dice are rolled and the two numbers showing are added to produce a sum between 2 and 12.
  3 件のコメント
Adam Danz
Adam Danz 2018 年 7 月 13 日
Not sure what you need. The sum function is either
x = a + b;
or
x = sum([a, b]);
Hannah Bartolo
Hannah Bartolo 2018 年 7 月 13 日
I was trying to asking what the code/ syntax would be for the six-sided dice are rolled and the two numbers showing are added to produce a sum between 2 and 12

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

回答 (1 件)

Adam Danz
Adam Danz 2018 年 7 月 13 日
To simulate a roll of a n-sided die, use the randi() function. You can generate two random integers between 1 and 6 (inclusive) with one function call.
Then all you need to do is use sum() on the results of randi(). This assumes the dice are fair.
You could do this in one line if you'd like
sum(randi()); %you fill in the parameters of randi

Community Treasure Hunt

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

Start Hunting!

Translated by