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

37 ビュー (過去 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 Center および File ExchangeDevelop 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