필터 지우기
필터 지우기

How do I show the for loop results over time?

조회 수: 1 (최근 30일)
Chase Williams
Chase Williams 2019년 3월 10일
편집: Kevin Phung 2019년 3월 10일
I need to create a grapgh of player 2's score over the number of "trials". However, I can only see the last score of the 10,000 trial. How can I save all of the data such that I know the score for the nth trial?Mathworks Q.PNG

채택된 답변

Kevin Phung
Kevin Phung 2019년 3월 10일
편집: Kevin Phung 2019년 3월 10일
n = 100000; %number of trials
score = zeros(n,2); % first column is player 1, 2nd column is player 2
for i = 1:n
p1 = randi([1 2])
p2 = randi([1 2])
if p1+ p2 == 3
score(i,:) = [ 1 0];
else
score(i,:) = [0 1];
end
end
%check score for 99th trial:
score(99,:)
%check total score:
sum(score)
  댓글 수: 2
Chase Williams
Chase Williams 2019년 3월 10일
Using this code, how would I plot player 2's score over each of the trials?
Kevin Phung
Kevin Phung 2019년 3월 10일
편집: Kevin Phung 2019년 3월 10일
plot(score(:,2)).
I would suggest you read up on array indexing

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

추가 답변 (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