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
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