How to repeat a for loop n times

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 comentario

James Tursa
James Tursa el 30 de Nov. de 2016
"... 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?

Iniciar sesión para comentar.

 Respuesta aceptada

James Tursa
James Tursa el 30 de Nov. de 2016
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 comentario

dpb
dpb el 30 de Nov. de 2016
NB: The existing loop can be replaced w/ a one-liner, though...

Iniciar sesión para comentar.

Más respuestas (2)

Jan
Jan el 30 de Nov. de 2016
Editada: Jan el 30 de Nov. de 2016
Simply include in a for loop:
n = 5;
for k = 1:n
.... your code
end
dpb
dpb el 30 de Nov. de 2016
Editada: dpb el 1 de Dic. de 2016
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.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 30 de Nov. de 2016

Comentada:

el 29 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by