Info

This question is closed. Reopen it to edit or answer.

How to assign values using several panels with RADIO Buttons in the GUI

1 view (last 30 days)
I made a GUI file with 3 panels of radiobuttons in order to get 3 values (1 or 0) for 3 different parameters. I run this GUI file in another script where I want to use the value's but an error occurs. Below a part of the GUI file for one of the parameters.
----------------------------------
% --- Executes on button press in SAM_radiobutton.
function SAM_radiobutton_Callback(hObject, eventdata, handles)
% hObject handle to SAM_radiobutton (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 SAM_radiobutton
if (get(hObject, 'Value') == get(hObject,'Max'))
sampresent = 1
end
% --- Executes on button press in GSAM.
function GSAM_Callback(hObject, eventdata, handles)
% hObject handle to GSAM (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 GSAM
if (get(hObject, 'Value') == get(hObject,'Max'))
sampresent = 0
end
end
----------------------------------
After running the other script this error occurs:
----------------------------------
??? Undefined function or variable 'sampresent'. Error in ==> Start at 161 sp = sampresent -1;
(161 sp = sampresent -1;)
----------------------------------
https://www.mathworks.com/matlabcentral/answers/41626 was not helpful
  1 Comment
Muthu Annamalai
Muthu Annamalai on 8 Jul 2013
Your hint is to use the property GUIDATA on handles structure. So you would do something like, replacing,
sampreset <-> handles.sampresent
in your code.
What this does is to pass around global data to all your callbacks.
Your hint is already in the MATLAB template code,
handles structure with handles and user data (see GUIDATA)

Answers (0)

Community Treasure Hunt

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

Start Hunting!