Interrupt running function with event in a GUI
7 views (last 30 days)
Show older comments
Hi, I want to use a GUI pushbutton to signal an event to a running function - in particular, to issue the 'keyboard' command in a misfit function which is being called by fminsearch (to investigate the state of the fitting process). Currently I use the following: Before calling fminsearch, main script opens a small GUI with a pushbutton with callback:
function pushbutton1_Callback(hObject, eventdata, handles)
global interrupt
interrupt=true;
...and in the misfit function:
global interrupt
%...
if interrupt, keyboard, interrupt=false; end
This works, but I have to hammer the pushbutton repeatedly to get a response (waiting after one push doesn't seem to work). There is already a drawnow command in the misfit function on each call, which apparently should allow Matlab to process outstanding events, but this does not seem to improve matters (neither does a pause(0.01)).
Can someone suggest a good way to do this which might be more responsive?
2 Comments
Geoff Hayes
on 31 Jan 2016
Mark - what else is the misfit function doing (is this something that you have written)? Perhaps it is "busy" and once it finishes evaluating whatever it is doing, then it checks the interrupt flag. Please post the code for this function (or an outline of it) so that we can get a better idea of what may be causing the delay.
Answers (2)
See Also
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!