How to know which radio button is selected in a radio button group in app designer of Matlab 2018a?

조회 수: 36 (최근 30일)
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

채택된 답변

Ajay Kumar
Ajay Kumar 2019년 10월 6일
" 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개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by