フィルターのクリア

How to get value of radiobutton (or togglebutton) in GUI from another function?

7 ビュー (過去 30 日間)
Carlos HM
Carlos HM 2018 年 6 月 22 日
コメント済み: Carlos HM 2018 年 6 月 23 日
I have a GUI file with only a togglebutton and a pushbutton. The following is the code of .m file of the GUI (without code of initialization):
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton12
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=load('data.mat');
s=1;
g=[];
while s<=length(a)
g(s)=s*a(s);
if get(handles.radiobutton1,'Value')==0
break
end
s=s+1;
end
Basically, I want to get the value of the radiobutton and while it is not selected (value is 0) keep concatenating s*a(s) to array g. Then, when radiobutton is selected (its value is 1) stop the concatenation (finish), even if s is still <=length(a). However, when I press the push button I get the following error "reference to non-existent field handles.radiobutton1". How could I solve it?
PS: instead of radiobutton I could use togglebutton if required.
Thank you for your help.
  3 件のコメント
Rik
Rik 2018 年 6 月 22 日
Despite your edit, the relevant code is still missing. The handle to the radiobutton object should be saved to the struct somewhere. That doesn't change if you replace it by a togglebutton. Evidently the radiobutton object handle is not saved to the guidata struct under the name you expect. You could use breakpoints to see what fields handles contains. Otherwise, getting al the figure children is still an option.
Carlos HM
Carlos HM 2018 年 6 月 23 日
Ok, thank you. I solved the problem. I previously removed handles from
function pushbutton1_Callback(hObject, eventdata, handles)
Instead of that, it was like this:
function pushbutton1_Callback(hObject, eventdata)
There was the problem.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by