Abort button on MATLAB GUIs

2 views (last 30 days)
Yakboy287
Yakboy287 on 23 Jan 2014
Commented: Yakboy287 on 24 Jan 2014
I've seen a lot of posts on this subject, but none of them answer the problem I'm having. I've got a GUI that controls a rotating platform used for scanning antennae over different angles. It steps through a series of angles, taking data at each step. I'm trying to get an abort button to work by setting a global handle's (to the abort button) value to 1 when the button is pressed, then checking this value via get(h,'Value') in the scan loop before each step and breaking the loop if the value is 1.
The problem I'm having is that the scan is taking priority over the abort button, so that the GUI doesn't aknowledge the abort being pressed until the full scan is done. This means that the value doesn't change to 1, so the abort never happens. Is there a way that I can make the scan part interruptable? Thank you!

Answers (1)

Image Analyst
Image Analyst on 23 Jan 2014
I've noticed that too. What I do is to have a checkbox that says "Finish Now". Then, in your loop, check the value and exit if it's checked.
set(handles.chkFinishNow, 'visible', 'on');
while true
% Your code
if get(handles.chkFinishNow, 'value')
break;
end
end
set(handles.chkFinishNow, 'visible', 'off');
  3 Comments
Image Analyst
Image Analyst on 23 Jan 2014
It might not update if it's in a really computationally intensive loop. Put a "drawnow" command after anytime you want to force the display to update.
Yakboy287
Yakboy287 on 24 Jan 2014
That actually worked not only to get it to update the position, but allowed the abort button to work as well. I also tried pause(0.1) which worked. Thanks very much! I guess it just needed something to briefly interrupt the calculation. James

Sign in to comment.

Categories

Find more on Simulink 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!