How can I restart a loop for the same iteration?

39 次查看(过去 30 天)
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 个评论
KL
KL 2017-12-12
(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.

请先登录,再进行评论。

回答(1 个)

Jos (10584)
Jos (10584) 2017-12-12
Use a while loop:
k = 0
while k < N
k = k + 1 ;
... do stuff
if ...
k = 0 ; % start again
end
end

类别

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