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 Exchange에서 Loops 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