Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

dice probability game with graph of results

Asked by Brian

Brian (view profile)

on 15 Jun 2013

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)
plot(Numberof6s,x)  %Don't know what to do here. 

Thanks for any help.



Brian (view profile)


No products are associated with this question.

1 Answer

Answer by the cyclist

the cyclist (view profile)

on 15 Jun 2013
Edited by the cyclist

the cyclist (view profile)

on 15 Jun 2013
Accepted answer

Try the cumsum() function instead of the sum() function, and I think you get what you intended.

You probably also want


rather than


1 Comment


Brian (view profile)

on 15 Jun 2013

thanks man!! it worked

the cyclist

the cyclist (view profile)

Contact us