How can I implement a function that does the equivalent of Ctrl-C?

조회 수: 13 (최근 30일)
I would like a command that does the equivalent of Ctrl-C so that I can programmatically quit out of my code. This would expecially be useful as a callback to a pushbutton.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2015년 8월 25일
There is no way to programmatically issue a Ctrl-C in MATLAB besides using the keyboard's Ctrl-C combination.
As an alternative, you can use the ERROR command to force an error that will exit the code. For example:
error('Program terminated for a specific reason')
  댓글 수: 2
Adam
Adam 2016년 8월 3일
error( ... ) should always return you to the command line unless you have a try-catch statement which handles the error, in which case it will continue.
Walter Roberson
Walter Roberson 2018년 12월 18일
error() with an empty string is aa special case that does not trigger an error . Historically it was used internally in Mathworks code.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by