while get uicontrol not working
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi all
I am using uicontrol to get value from user . I am using while loop to run until checkbox is checked.
fig = figure;
scrsz = get(0,'ScreenSize');
set(fig,'Position',[scrsz(3) - 400,scrsz(4)-400, scrsz(3)/6,scrsz(4)/10]);
h = uicontrol('Style', 'checkbox',...
'Position',[20 20 200 40],...
'String','Stop program ');
drawnow % must to do this in order to view checkbox
while (1 && ~get(h,'Value'))
%%do somthing....
end
When I run this program I am stucked in the while loop despite of checking the checkbox.
it works ok only in debug mode !!
1) Why it's workking only in debug mode?
2) Why the checkbox is not visible and I must typing drawnow(in debug mode it's work ok)?
Any help will be appreciated.
댓글 수: 0
채택된 답변
Jan
2011년 2월 20일
The contents of the figure is updated 1. when the command prompt gets active, or 2. when DRAWNOW or 3. PAUSE is called. In debug-mode the command prompt mechanism triggers the update of the figure and processes the queued events. In non-debug mode DRAWNOW is necessary to perform this, which is a wanted and documented behaviour.
Therefore you have to insert a DRAWNOW in your WHILE loop also to allow the checkbox to update its value.
BTW: In "1 && ~get(h,'Value')" the "1&&" is not needed.
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!