Azzera filtri
Azzera filtri

for loop start from first operation if df=1?

1 visualizzazione (ultimi 30 giorni)
Arunachalam  D
Arunachalam D il 14 Lug 2015
Risposto: Geoff Hayes il 14 Lug 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

Risposte (1)

Geoff Hayes
Geoff Hayes il 14 Lug 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.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by