GUI made without GUIDE not updating

I'm trying to make a GUI that pops up as soon as the main function starts and it contains a checkbox that can be used to stop the program when it is in a loop:
function mainFcn
h.fig = figure('Position', [100 100 100 100]);
h.cancelBox = uicontrol('Style', 'checkbox',...
'String', 'Cancel?',...
'Position', [10 10 10 10]);
set(h.cancelBox, 'callback', {@cancelBox, h});
drawnow;
i = 1;
while i == 1
value = get(h.cancelBox, 'Value');
if value == 1
i = 0;
else
i = 1;
end
end
function cancelBox(hObject, eventdata, handles)
set(hObject, 'Value', 1);
guidata(hObject, handles);
When I use disp(value); to see the value I am getting for the current value of the checkbox. It always says that the checkbox has a value of 0.

 採用された回答

Walter Roberson
Walter Roberson 2015 年 8 月 5 日

0 投票

i == 0 is not an assignment statement.
Also your while loop is not giving an opportunity for any graphics interruptions. Graphics interruptions are only processed when there is a pause(), drawnow(), uiwait() or waitfor(), figure(), or the routine reaches the command prompt.

1 件のコメント

qward
qward 2015 年 8 月 5 日
The i == 0; was an typo I'm sorry about that. But I tried using drawnow() and it worked perfectly thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

質問済み:

2015 年 8 月 5 日

編集済み:

2015 年 8 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by