How to create a callback for radio buttons

79 views (last 30 days)
I have a group of radio buttons with 3 choices (app.mode1, app.mode2, and app.mode3) in app-designer. When a user clicks one of the radio buttons, I want the name of a separate button to be changed to something else. For example: mode 1: "load", mode 2: "plot", mode 3: "display". I'm able to create a call back for the group of radio buttons as below:
function modeSelectionChanged(app, event)
selectedButton = app.mode.SelectedObject;
But I have no idea as to how to write the following codes. Would someone please help me out?
Many thanks!

Accepted Answer

Cris LaPierre
Cris LaPierre on 16 Mar 2021
Edited: Cris LaPierre on 16 Mar 2021
Assuming your button has the name app.Button, and your radio buttons are labeled 'Mode1', 'Mode2', and 'Mode3', something like this
% Selection changed function: Mode
function ModeSelectionChanged(app, event)
selectedButton = app.Mode.SelectedObject;
switch selectedButton.Text
case 'Mode1'
app.Button.Text = "Load";
case 'Mode2'
app.Button.Text = "Plot";
case 'Mode3'
app.Button.Text = "Display";
Leon on 16 Mar 2021
That was indeed the problem!
I had the previous issue because I was using selectedButton.Text, but in my cases, they were the Values. Now it is working.
Many thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!