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 Kommentar

Jan
Jan am 15 Mär. 2012
Please post the code instead of describing it.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 15 Mär. 2012

0 Stimmen

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

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 15 Mär. 2012

Community Treasure Hunt

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

Start Hunting!

Translated by