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 commentaire

Jan
Jan le 15 Mar 2012
Please post the code instead of describing it.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 15 Mar 2012

0 votes

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

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Question posée :

le 15 Mar 2012

Community Treasure Hunt

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

Start Hunting!

Translated by