How can I restart a loop for the same iteration?
39 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear all,
Maybe this question sounds odd, but I wonder how I could restart a if-loop for the same iteration (if the user asks for it).
So right now I draw a figure, then I ask the user what to do (Letters coded in a choice/if loop). And one of the options should be to redraw the figure and give again all the options. I think I have to use a while loop from the beginning, but I am afraid I have no idea how to do that...
Thank you for your help,
Katharina
So atm my code looks a bit like
for ... loop through files
... open file, prepare data, draw figure
choice = input ...
if choice== 'A'
... do stuff with data and exit if loop
if choice== 'B'
... do other stuff with data and exit if loop
if choice== 'C'
... do stuff
... redraw figure and prompt again these options (???)
end
save changed data
end
2 Commenti
KL
il 12 Dic 2017
(Letters coded in a choice/if loop)
I'd recommend switch case for this purpose and then you can follow Jos' answer to reset the condition variable.
Risposte (1)
Jos (10584)
il 12 Dic 2017
Use a while loop:
k = 0
while k < N
k = k + 1 ;
... do stuff
if ...
k = 0 ; % start again
end
end
0 Commenti
Vedere anche
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!