Exiting from a script without closing MATLAB

조회 수: 323 (최근 30일)
David
David 2014년 4월 11일
댓글: Joe Privacy 2021년 3월 5일
While writing my MATLAB script, I've found that exiting the script is done by adding the line
exit
... which does end the script - but it also closes MATLAB completely.
How can I prematurely end a script, without closing MATLAB?
- As one possibility, is there a way to jump to / skip to / go to a line at the end of the script file?
- Are there other, better possibilities?
Here's what I have so far:
Mode = menu('Choose a Difficulty: ', 'Easy', 'Medium', 'Hard', 'Expert')
switch Mode
case (1)
...
case (2)
...
case (3)
...
case (4)
...
otherwise
button = menu('Giving up already?','Yes','No');
switch button
case 1,
display('Exiting Game');
savefile = 'GameBestTime.mat';
save(savefile,'BestTime');
exit
case 2,
quit cancel;
case 0,
quit cancel;
end
end

채택된 답변

Walter Roberson
Walter Roberson 2014년 4월 11일
You could throw an error, but you probably don't want to do that.
The code you show would be in a loop. Change the "exit" to "break" to cause the code to exit the loop and continue on with the next statement after the loop.
  댓글 수: 1
Joe Privacy
Joe Privacy 2021년 3월 5일
This is neither an answer, or a clean approach to terminating a script without completely quiting Matlab.
zzzhhh's response below is the correct answer to the problem.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

zzzhhh
zzzhhh 2018년 4월 16일
return;

David
David 2014년 4월 11일
For some reason, that wasn't working yesterday. But it is now, for some reason.
Alright, thanks!

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by