Enable/disable on radio button in app designer

In App Designer, I have created a radio button group with three buttons. The buttons select which set of data to graph. Call the three buttons Choice1, Choice2, and Choice3.
If a certain selection of other controls is made in the app, I want to disable the Choice2 and Choice3 buttons and force the selected button to be Choice1.
If different set of selections is made, I want to re-enable the other Choice2 and Choice3 buttons and allow them to be selected.
Is it possible to do this? If so, how?

 Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Jun. de 2025
You can create app.bg as a uibuttongroup and populate it with uiradiobutton .
Later, you can
bc = [app.bg.Children];
set(bc(1:end-1), 'Enable', 'off')
bc(end).Enable = 'on';
app.bg.SelectedObject = bc(end);
to enable the first button and disable the other objects.
To restore,
bc = [app.bg.Children];
set(bc, 'Enable', 'on');
app.bg.SelectedObject = bc(end);

3 comentarios

Thank you. This was very helpful.
It turns out that when I created my buttons the one I want to keep enabled is number 3. So the code I've found that works is:
bc = [app.bg.Children];
set(bc(1:2), 'Enable', 'off') % Disable buttons 1 and 2
bc(3).Value = 1; % Force button 3 to be selected
and to re-enable:
bc = [app.bg.Children];
set(bc, 'Enable', 'on'); % Enable buttons 1 and 2
In the actual calback function, the only code I'm using is a call to the graphing function (which is also called by other callbacks). Within the graphing function, I'm using a switch to determine which button was selected.
switch app.bg.SelectedObject.Text
case "Choice1"
case "Choice2"
case "Choice3"
end
This seems a little clunky, but the alternative would be dealing with the array of app.bg.Children.Value, which might look like this [0, 1, 0]. Is there a better way to get the choice numerically (that wouldn't break if the texts changed)?
You could set the UserData property of each of the button children, set it to an index. Then
app.bg.SelectedObject.UserData
would give you the index
Or you could
[tf, idx] = ismember(app.bg.SelectedObject, app.bg.Children);
and then if tf is true, idx would be the index in reverse creation order (e.g, if there were 3 children then index 3 would correspond to the first created.)
Jim McIntyre
Jim McIntyre el 30 de Jun. de 2025
Thank you for the additional suggestions.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Update figure-Based Apps en Centro de ayuda y File Exchange.

Productos

Versión

R2025a

Preguntada:

el 25 de Jun. de 2025

Comentada:

el 30 de Jun. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by