Borrar filtros
Borrar filtros

Use dynamic "offset" in a for-loop

3 visualizaciones (últimos 30 días)
Sten
Sten el 9 de Mzo. de 2015
Comentada: Sten el 9 de Mzo. de 2015
Hi, I have a loop that starts with
for t = window:offset:numel(m);
However, I would like the "offset" value to be dynamic and adjust after each loop by:
offset=0;
for i = x:numel(m);
if m(i,:) == true;
for x = i+1:numel(m);
if m(x,:) == false;
offset = offset+1;
else
offset=offset+1;
break,
end
end
else
break;
end
end
In this case, "m" is a vector of logical values where "1" is a monthly break. Hence, "offset" is the number of (in this case) trading days for each month.
Any suggestion of how I could accomplish this?
Many thanks, Sten

Respuesta aceptada

Andrew Newell
Andrew Newell el 9 de Mzo. de 2015
It would be better to use a while loop to increment t directly:
t = window;
while t < numel(m)
% increment t instead of offset
end
The code you use to adjust offset has some serious problems, including this use of x:
for i = x:numel(m);
...
for x = i+1:numel(m);
  1 comentario
Sten
Sten el 9 de Mzo. de 2015
Many thanks Andrew, I tried a while-loop instead. Haha yep I need to check that part through. Br, Sten

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by