Borrar filtros
Borrar filtros

while get uicontrol not working

2 visualizaciones (últimos 30 días)
zohar
zohar el 20 de Feb. de 2011
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.

Respuesta aceptada

Jan
Jan el 20 de Feb. de 2011
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.

Más respuestas (1)

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

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by