How to know which radio button is selected in a radio button group in app designer of Matlab 2018a?
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Installation and Setup en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!