Can I Use the Special Function Keys to Interrupt a Script?

Back in the old QuickBasic and early Visual Basic days I would write code that allow me to interrupt a running algorithm by pressing a special function key. Is there a similar function in today's Matlab?
Thanks,
Dave

 採用された回答

Walter Roberson
Walter Roberson 2012 年 8 月 23 日

0 投票

If you have a graphics involved, then you can set a WindowKeyPressFcn callback.
However, handle graphics callbacks are only given control under limited circumstances, such as if there is a pause() or drawnow() call. If your code is pure computation, then if the computation is mostly at the MATLAB level then timers can interrupt them; if the pure computation is built-in or MEX routines then there isn't any way to interrupt other than control-c.

その他の回答 (1 件)

Kye Taylor
Kye Taylor 2012 年 8 月 23 日

0 投票

Ctrl+C will kill a running script/function

2 件のコメント

David Koenig
David Koenig 2012 年 8 月 23 日
Yes, but I do not want to stop the script/function. Instead I want to be able to carry out another short function and get back to the algorithm that I interrupted. I don't think CRTL-C would allow that. Thanks anyway.
Kye Taylor
Kye Taylor 2012 年 8 月 23 日
Forgive me if you know about breakpoints and using the debugger, but you can place the command
keyboard
in a script, and it will pause execution of the script just like a breakpoint. Althought this requires knowing a priori where you want stop a scripts execution.
Another alternative is to set a conditional/error breakpoint that will pause execution when a condition is met that you specify.

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

カテゴリ

ヘルプ センター および File 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