I have created a button group with four radio buttons and a push button using guide.
There are four functions, one for each radio button written separately.
- How do you to call these functions from respective radio buttons.
- When a push button is pressed, the function associated with the active radio button should execute.
Crash course on GUI's starts... now:
If you're using
guide
, then when you save your figure mygui.fig, the M-file should be automatically generated as mygui.m. Open up mygui.m and enter your code under the radio button callback function. Any variables that you want initialized when you start the program should be defined under the opening function. Make sure you update the handles structure at the end of each callback, with the command guidata(hObject,handles).For example, if you wanted two mutually exclusive radio buttons (when you select one, the other de-selects, or when you de-select one, the other is selected), enter the following code under their callbacks:
and
And initialize radio button one to be selected under the opening function:
A solution for the Button Group Callback: SelectionChangeFCN
Use the Selection Change callback property (right click on the Button Group and select View Callbacks->SelectionChangeFcn) of the uipanel. The eventdata argument contains the handles to the current and previously selected radiobutton. The eventdata argument is a structure with the following fields:
So, depending on the value of eventdata.NewValue; for example
A solution for the push button callback
The callback for your push button could have something along the lines of
I also refer you to the MATLAB documentation for more information on Handle Graphics and building graphical user interfaces.