Effacer les filtres
Effacer les filtres

for loop start from first operation if df=1?

1 vue (au cours des 30 derniers jours)
Arunachalam  D
Arunachalam D le 14 Juil 2015
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

Réponses (1)

Geoff Hayes
Geoff Hayes le 14 Juil 2015
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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by