필터 지우기
필터 지우기

How do i write a loop statement?

조회 수: 1 (최근 30일)
Nick Haufler
Nick Haufler 2015년 9월 29일
답변: Image Analyst 2015년 9월 29일
Im struggling to write a loop statement for part B in the pdf attached. I looked on mathworks for help, and they showed the x(n) = 2 * x(n - 1); statement. Am i also suppose to have this in my code? I attached my code, I just want some direction on how to write this.

채택된 답변

Image Analyst
Image Analyst 2015년 9월 29일
You don't use that formula - it doesn't apply at all. Just create a histogram by counting the numbers for each roll
counts = zeros(1,6); % list of how many times each number came up
for r = 1 : numRolls
roll = randi([1 6],1);
counts(roll) = counts(roll)+1;
end
% Now normalize to get fraction of time each number came up.
counts = counts / numRolls; % Multiply by 100 if you want percentage instead of a fraction.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by