How can I interrupt a callback and NOT come back to finish its execution in MATLAB?

조회 수: 70(최근 30일)
I have a GUI with a callback. When the callback is interrupted during a loop, the interrupting function executes and then MATLAB returns to finish the execution of the interrupted callback. I would like MATLAB to exit the original loop once the interrupting function has finished executing.
I have tried setting the 'Interruptible' and 'BusyAction' properties of the UICONTROL to all different combinations, and nothing seemed to help.
For example, in the attached file 'testinterrupt', after entering the 1st loop, if I press the pushbutton again, MATLAB will enter loop 2, but return and finish loop 1 after loop 2 is done executing.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2020년 5월 8일
편집: MathWorks Support Team 2020년 5월 8일
The ability to have the interrupted function stop executing after the interrupting function is completed is not automatically available in MATLAB.
However, it is possible, as shown in the attached example "interrupt_stop", to code this logic into the loop. Notice the callback structure for PushButton1:
Inside the FOR loop, once the callback is interrupted, the function will execute completely, and then return to where it left inside the FOR loop. Eventually it will reach the IF statement with a TRUE condition, which will trigger the execution of the RETURN command, and therefore stop the execution of the original callback.
In this example, the functions SETAPPDATA and GETAPPDATA are used. These functions allow for the creation of user-defined properties, in this case "Callbackrun".
Example is now included. Please note this question is intended for the R2006b release of MATLAB and the example might not work in newer releases.* If you are still having an issue with callbacks, please try MATLAB App Designer (the replacement for GUIDE), or contact MathWorks technical support. *
  댓글 수: 3
Dan Hendrickson
Dan Hendrickson 2020년 5월 8일
I've attached the original example. Please read the last paragarph of the MathWorks answer for more information.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

tommsch 2020년 11월 23일
I think I found a solution. See my proof-of-concept submission errorat at the Matlab Fileexchange. A similar approach should be possible with the use of callbacks. Since I never used callbacks before, I cannot tell you more, but I am strongly convinced it is possible.
errorat injects a call to clear all in every line of a function - thus, making it very likely that the function will crash.





Community Treasure Hunt

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

Start Hunting!

Translated by