What to do with for-while loop?
조회 수: 1 (최근 30일)
이전 댓글 표시
The question is "Create the matrix based on the probabilities [0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125] until you get the 1st 8 "
So apparently the question is only asking for the u's and b's so I do not have to compute the list of s. Apparently I need a for-while-loop to fill in values of u and b. How should I do the for-while loop though?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/951329/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/951369/image.png)
댓글 수: 2
Torsten
2022년 4월 3일
u = rand()
gives you only one random number.
So over what do you sum in the next line of your code ?
답변 (1개)
Torsten
2022년 4월 3일
number_on_dice = 6;
bu = [ ];
while number_on_dice ~= 8
u = rand();
number_on_dice = sum(cdf <= u) + 1;
bu = [bu;[u,number_on_dice]];
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!