To roll 4 dices at the same time

i want to create a program in matlab about rolling 4 dices (fair dices, 6 sided) at the same time, and then assign them the probabilities. then i have to conduct n trials of the experiment and plot it also please help me, please write a ful matlab code am v poor in matlab

댓글 수: 2

Jan
Jan 2011년 9월 18일
Writing full MATLAB code is not usual in this forum. If your MATLAB skills are too low to complete the program, do this in another programming language you are more familiar with.
Muhammad Abdullah
Muhammad Abdullah 2011년 9월 18일
ok

댓글을 달려면 로그인하십시오.

 채택된 답변

Image Analyst
Image Analyst 2011년 9월 18일

0 개 추천

Use the randi function. It's so simple it's hard to guide you without doing the whole thing for you but I'll try:
numberOfRolls = 100;
numberOfDice = 6;
distribution = zeros(6,1);
for roll = 1 : numberOfRolls
diceValues = randi(6,[numberOfDice 1]);
% Accumulate into the distribution.
for die = 1 : numberOfDice
distribution(diceValues(die)) = % You figure it out.
end
end
% Plot it.
bar(% You figure it out.);

추가 답변 (1개)

Image Analyst
Image Analyst 2011년 9월 18일

0 개 추천

Do you need me to spell out the needed adaptations?
numberOfDice = 4;
because you wanted 4 dice, not 6, and
distribution(diceValues(die)) = distribution(diceValues(die)) + 1;
to store your results for this roll, and
bar(distribution);
to do the plotting of the distribution. Now you have everything. Certainly it can't be that tough to figure out now! I think you really need to at least scan through the "Getting started" section because the code I posted was very simple, basic, and self explanatory and should have been easily understood by anyone who has done any programming at all.

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by