Handle manual breaks

Hi All,
I'm not sure if this is possible, but has anyone come across a way to handle manual breaks in code? i.e. if you Ctrl+C out of a loop, can you make the code respond to that?
An alternative would be making a popup button that you could press to stop the code, and then have the code do other things once you hit the button, but that seems like it might require 2 threads, one to make and monitor the button while the other executes code.
Thanks for any advice

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 2 月 27 日

0 投票

control-C can never be caught.
The button approach doesn't really require two threads in any meaningful way. The code doing the work would have to occasionally have drawnow() or figure() or pause() calls in order to give a chance for the user interface to act on accumulated events; when it does so, it interrupts the active code, runs the callback and returns to the existing code. The callback can set a variable whose value is checked in the main code, with the main code voluntarily quiting when it sees that value.

1 件のコメント

Darin
Darin 2012 年 2 月 27 日
Thanks! do you know of a good button function that will allow the code to continue, not waiting for its response?

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2012 年 2 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by