Reassigning value in a for loop

i have created a vector of intergers between certain values
i am going through each element of the vector and depending on its value executing different commands. however if certain numbers come up, then a new set of commands are executed until that number appears again.
i have set this up with an if statement inside a for loop and at the end of the if statement when the number has appeared again i would like to reset the original value of the for loop so that it can take into account the number of steps that occured before the number reappeared again. so that the values in the original vecotr are not repeated again.
when i reassign the value at the end of the initial for loop it resets to the next number it should be in the loop. it makes logical sense that thats what it should do but how could i change this??

1 comentario

Jan
Jan el 15 de Mzo. de 2012
Please post the code instead of describing it.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 15 de Mzo. de 2012

0 votos

I assume that you want to use a while loop:
v = 1:100;
k = 0;
while k <= length(v)
...
k = k + 1;
% or set k as wanted
% Modifying [v] is possible also
end

Categorías

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

Preguntada:

el 15 de Mzo. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by