Borrar filtros
Borrar filtros

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

7 visualizaciones (últimos 30 días)
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 comentarios
Rik
Rik el 22 de Jun. de 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.
Carlos HM
Carlos HM el 23 de Jun. de 2018
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by