How to get value of radiobutton (or togglebutton) in GUI from another function?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Rik
le 22 Juin 2018
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.
Réponses (0)
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!