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!

답변 (1개)

Image Analyst
Image Analyst 2014년 1월 23일

0 개 추천

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

I tried your suggestion, but I get the same problem. Actually, it doesn't even set it to visible during the scan, but even when I have it always visible, when I click it, it doesn't evaluate the change until after the scan completes. I'm having other issues with GUI input/output as well that may be related. For instance, it runs a function to update a position indicator each step, but the changes don't show up on the GUI until the scan is done (then the position is updated to the final position correctly).
Here is what I'm doing as far as the check box goes, maybe you can spot a flaw:
testBox = uicontrol('parent',p1,'style','checkbox'); % p1 is the handle to
% the GUI panel
set(testBox,'position',[0 10 50 20]);
set(testBox,'string','abort');
set(testBox,'value',0);
% set(testBox,'visible','off');
function Scan(source, ~)
% set(testBox,'visible','on');
for scanLoop=1:x
if get(testBox,'value')
break
end % end if
<scan code>
end % end for
% set(testBox,'visible','off');
end % end function
Thank you!
Image Analyst
Image Analyst 2014년 1월 23일
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 2014년 1월 24일
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

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

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

질문:

2014년 1월 23일

댓글:

2014년 1월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by