Question regarding function using radiobutton status

Lets say I have three radio buttons. If 1 is pressed, then variables x,y,z are certain values. If 2 is pressed, then variables x,y,z are different values, etc.
How would I write a function that outputs those variables and use it within the GUI code?

 Accepted Answer

Greg - consider placing your three radio buttons in a button group panel and assigning a SelectionChangeFcn callback to this panel. Whenever the user selects a radio button, this callback will fire and you will be able to changes the variables as you see fit based on the selected radio button
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
selectedRadioBtnStr = get(hObject,'String');
if strcmpi(selectedRadioBtnStr, 'Radio Button 1')
handles.x = 1;
handles.y = 2;
handles.z = 3;
elseif strcmpi(selectedRadioBtnStr, 'Radio Button 2')
handles.x = 11;
handles.y = 21;
handles.z = 31;
elseif strcmpi(selectedRadioBtnStr, 'Radio Button 3')
handles.x = 111;
handles.y = 211;
handles.z = 311;
end
guidata(hObject,handles);
We then save those changes to the handles structure using guidata. See the attached for an example.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Asked:

on 30 May 2016

Answered:

on 4 Jun 2016

Community Treasure Hunt

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

Start Hunting!