Setting .m file to Radio Button in GUI Creator

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!

1 Comment

As a matter of user interface design:
Radio buttons are used to select between options, but they do not typically trigger actions (other than perhaps to change the set of optional parameters that are available to be filled in.)
When you want to trigger action such as "Analyze the data using analysis type #3" then you should use push buttons instead of radio buttons.
Radio buttons can trigger actions, and can be used to trigger data analysis, but this is not their role in user interfaces. Remember that when you select a particular radio button, it stays selected (unless you deliberately reset it), which would prevent you from selecting that same analysis type a second time in a row, which is not a problem for push buttons.

Sign in to comment.

 Accepted 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.

More Answers (0)

Categories

Find more on Update figure-Based Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!