필터 지우기
필터 지우기

How can I restart a loop for the same iteration?

조회 수: 40 (최근 30일)
KatPa
KatPa 2017년 12월 12일
댓글: KL 2017년 12월 12일
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
Birdman
Birdman 2017년 12월 12일
Share your code please.
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