MATLAB: Setting .m file to Radio Button in GUI Creator

functionguiradio button

Hey there,
I am currently trying to make a GUI interface using the built-in MATLAB builder. I want to set 4 separate radio buttons to 4 separate functions, so that by selecting one, the "analysis type" is selected by the user.
I also want these functions to read the data that has been exported into the GUI through a .xlsx file. I have the import command set for this, just need those radio buttons to read the data.
Any help would be appreciated.
Thanks everyone!

Best Answer

Using GUIDE (which is presumably what you mean by the built-in MATLAB builder, create a button group panel and create the four radio button within this panel. (We do this so that only one radio button will be enabled/on at a time.) This panel has a SelectionChangeFcn callback which will fire whenever one of the four radio buttons is selected. Depending upon which button is selected, you will want to call one of your four functions. For example, using the example from radio button group callback, you could do something like
function uibuttongroup1_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uibuttongroup1
% eventdata structure with the following fields
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
case 'radiobutton1'
% call function 1
case 'radiobutton2'
% call function 2
case 'radiobutton3'
% call function 3
case 'radiobutton4'
% call function 4
end
If the data from your Excel file has already been read by your GUI, then you could - at the time of reading - save this data to the handles structure so that you can refer back to it from the uibuttongroup1_SelectionChangedFcn callback via the handles input parameter. See guidata for details.