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

Jan
Jan 2012년 3월 15일
Please post the code instead of describing it.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2012년 3월 15일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2012년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by