while get uicontrol not working

2 次查看(过去 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.

采纳的回答

Jan
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.

更多回答(1 个)

zohar
zohar 2011-2-20
Hi Jan
Thank you for your response!
.
.
.
while (~get(h,'Value'))
drawnow
%%do somthing....
end
This work excellent !!
Thanks again.

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by