Random values by default? [GUI]

1 回表示 (過去 30 日間)
mec123
mec123 2016 年 8 月 11 日
コメント済み: mec123 2016 年 8 月 12 日
Hi,
i created the following script:
function pushbutton1_Callback(hObject, eventdata, handles)
global cb7;
global cb8;
if (cb7 == 0)
%(action1)
end
if (cb8 == 0)
%(action2)
end
function checkbox7_Callback(hObject, eventdata, handles)
a=get(hObject,'Value');
global cb7;
if (a==1)
cb7=0;
else
cb7=1;
end
function checkbox8_Callback(hObject, eventdata, handles)
a=get(hObject,'Value');
global cb8;
if (a==1)
cb8=0;
else
cb8=1;
end
When i push the button, cb7 is "1" and cb8 is "0". How can that be? Only when i check and uncheck the boxes before pushing the button, both are "1".
Is it possible to set a default value?
Greetings

採用された回答

Geoff Hayes
Geoff Hayes 2016 年 8 月 11 日
mec123 - you can set default values in the OpeningFcn of your GUI. Just do
set(handles.checkbox8,'Value',1);
to set the checkbox as checked and
set(handles.checkbox8,'Value',0);
to set the checkbox as unchecked.
Also, there is no need to use global variables. If you want one callback to access the values of the other controls, then use the handles structure as
function pushbutton1_Callback(hObject, eventdata, handles)
if get(handles.checkbox7,'Value') == 0
% do action 1
end
if get(handles.checkbox8,'Value') == 0
% do action 1
end
  1 件のコメント
mec123
mec123 2016 年 8 月 12 日
Thank you, that helped a lot. Im pretty new to matlab (as you probably can tell^^) and still learning, so i appreciate it ;).

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by