フィルターのクリア

key to end program at any point

3 ビュー (過去 30 日間)
Lynn Pang
Lynn Pang 2019 年 4 月 5 日
回答済み: Walter Roberson 2019 年 4 月 6 日
i would like to set a specific key (let say the letter a) that will enable termination at any point during the running of m file ,
i tried 'input' but it required immediate response. ' get keywait will also not work .
i am a bit stuck and would be grateful for some guidance .
thanks
  1 件のコメント
A. Sawas
A. Sawas 2019 年 4 月 6 日
Wouldn't Ctrl+C do that for you?
To include a callback function that listens to key events, you need to have graphical objects such as Figures. See this page in matlab documentation "Callbacks — Programmed Response to User Action"

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 4 月 6 日
The only way to do that in MATLAB would be to use some kind of "hotkey" software that detected your key stroke and used the appropriate operating system facility to terminate the MATLAB process, such as Windows "taskkill" or Unix "killall" .
Above, A. Sawas mentioned control-C. Control-C does not meet your requirements for "immediate response". Control-C does not have any effect until the next time that MATLAB checks for interruption. MATLAB does not check for interruption in several circumstances:
  • executing inside the symbolic engine
  • executing inside the high-speed mathematics libraries
  • while waiting for the operating system to swap memory
  • while running a .dll or mex file
  • while processing calllib()
If MATLAB follows common code safety practices, it would not check for interruptions while doing memory allocation (too much risk of getting inconsistent memory states).
It is not clear whether MATLAB processes interrupts while executing any one "built-in function".
Because of these various times when MATLAB does not check for interruptions, there can be very significant delays before MATLAB responds to control-C -- days even, if you ask MATLAB to do something large and symbolic. The only way to get certain immediate response is to terminate MATLAB (even then, response can take time if MATLAB is busy calling into the operating system and it has locked interrupts to prevent inconsistent state.)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by