This:
v = zeros(1,NToys);
NRolls = 0;
needs to be inside your Trial loop so that it resets for each trial.
A simpler way to create your w:
Your while loop condition is that if any v is not equal to its w counterpart, so
v~=w is a vector result and is not doing what you expect for the conditional test. Or you could have used:
And after your while loop is over, you need to remember the number of rolls it took for this trial. E.g.,
NRolls_trial(Trial) = Nrolls;
Then you can average them when it is all over.
7 件のコメント
Rik (view profile)
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/490789-rolling-all-six-numbers-on-a-six-sided-die#comment_766678
Steven Lord (view profile)
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/490789-rolling-all-six-numbers-on-a-six-sided-die#comment_766682
Rik (view profile)
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/490789-rolling-all-six-numbers-on-a-six-sided-die#comment_766689
Rik (view profile)
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/490789-rolling-all-six-numbers-on-a-six-sided-die#comment_766704
KALYAN ACHARJYA (view profile)
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/490789-rolling-all-six-numbers-on-a-six-sided-die#comment_766710
KALYAN ACHARJYA (view profile)
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/490789-rolling-all-six-numbers-on-a-six-sided-die#comment_766713
James Tursa (view profile)
Direct link to this comment
https://it.mathworks.com/matlabcentral/answers/490789-rolling-all-six-numbers-on-a-six-sided-die#comment_766734
サインイン to comment.