How to repeat a for loop n times

조회 수: 182 (최근 30일)
MK96
MK96 2016년 11월 30일
댓글: Karthika AR 2020년 9월 29일
end
States
Basically it outputs an array of size (N,1) consisting of 1s and -1s.
How can I repeat this array for example 5 times using the updated values of 'States', whilst displaying the results of each loop?
  댓글 수: 1
James Tursa
James Tursa 2016년 11월 30일
"... using the updated values of 'States' ..."
What does this mean? I don't see 'States' used anywhere in the loop. Certainly you could wrap your current loop inside another loop, but how is 'States' supposed to be used in this loop?

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

채택된 답변

James Tursa
James Tursa 2016년 11월 30일
Is this all you are trying to do?
n = number of times to repeat the loop
States = zeros(size(N,1));
for k=1:n
for ii = 1:numel(AgentZScore)
% etc
end
States
end
  댓글 수: 1
dpb
dpb 2016년 11월 30일
NB: The existing loop can be replaced w/ a one-liner, though...

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

추가 답변 (2개)

Jan
Jan 2016년 11월 30일
편집: Jan 2016년 11월 30일
Simply include in a for loop:
n = 5;
for k = 1:n
.... your code
end

dpb
dpb 2016년 11월 30일
편집: dpb 2016년 12월 1일
Above loop can be simply
states=2*(cdf('norm',z,0,1)>rand(size(z)))-1;
where z <--> AgentZScore
To repeat, simply incorporate in a loop save each trial as a new column in 2D array would be simplest.

카테고리

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