Interrupt running function with event in a GUI
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
Geoff Hayes
2016-1-31
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.
回答(2 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!