while get uicontrol not working

6 ビュー (過去 30 日間)
zohar
zohar 2011 年 2 月 20 日
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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by