How to know which radio button is selected in a radio button group in app designer of Matlab 2018a?
34 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
M. Umar Naeem
le 6 Oct 2019
Réponse apportée : Ajay Kumar
le 6 Oct 2019
I have tried a lot, but still can't make it work. My problem is that except the default button that is selected in the radio button group, no other radio button has the property 'value' therefore checking for the value of selected button using ifs is not working. Here is the code where the radio button group and buttons are created which is non-editable.
% Create DirectionButtonGroup
app.DirectionButtonGroup = uibuttongroup(app.TranslateImagePanel);
app.DirectionButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @DirectionButtonGroupSelectionChanged, true);
app.DirectionButtonGroup.Title = 'Direction';
app.DirectionButtonGroup.SizeChangedFcn = createCallbackFcn(app, @DirectionButtonGroupSizeChanged, true);
app.DirectionButtonGroup.Position = [11 99 100 111];
% Create RightButton
app.RightButton = uiradiobutton(app.DirectionButtonGroup);
app.RightButton.Text = 'Right';
app.RightButton.Position = [11 65 58 22];
app.RightButton.Value = true;
% Create LeftButton
app.LeftButton = uiradiobutton(app.DirectionButtonGroup);
app.LeftButton.Text = 'Left';
app.LeftButton.Position = [11 43 65 22];
% Create UpButton
app.UpButton = uiradiobutton(app.DirectionButtonGroup);
app.UpButton.Text = 'Up';
app.UpButton.Position = [11 21 65 22];
% Create DownButton
app.DownButton = uiradiobutton(app.DirectionButtonGroup);
app.DownButton.Text = 'Down';
app.DownButton.Position = [11 0 65 22];
So, how can I determine if other buttons are selected when they don't have a value property. Here's the callback which should store the result of selected button in 'app.direction' property which is global.
% Selection changed function: DirectionButtonGroup
function DirectionButtonGroupSelectionChanged(app, event)
end
0 commentaires
Réponse acceptée
Ajay Kumar
le 6 Oct 2019
" no other radio button has the property 'value' "
Every radiobutton has the property Value.
In this case
app.RightButton.Value = true;
and all other radio buttons value will be false.
For, checking you can use if, as you written. It works like this
if app.LeftButton.Value = true
% do something
elseif app.UpButton.Value = true
% do something
% continue checking for other buttons
end
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!