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
2012-3-15
Please post the code instead of describing it.
回答(1 个)
Jan
2012-3-15
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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!