for loop start from first operation if df=1?

1 次查看(过去 30 天)
For a=1:20
Df=0;
If condition
Operation(a);
Condition reset;
Df=df+1;
End
If df==1
Repeat for loop again how to do it
End

回答(1 个)

Geoff Hayes
Geoff Hayes 2015-7-14
Arunachalam - I think that you may be able to repeat the above if you use a while loop. Something like
a = 1;
while a <= 20
if condition
Operation(a);
% Condition reset;
a = 1;
else
a = a + 1;
end
end
Not sure if the above is what you have intended but look how we just use a and not the Df to continue iterating or to restart the loop if some condition is met.
Note that the above code is dangerous as you could get stuck in an infinite loop. You may want to decide how many reset of a to one you should allow before terminating the while loop.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by