while get uicontrol not working
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Jan
am 20 Feb. 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.
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!