Index value for button group
6 views (last 30 days)
Show older comments
Ye Ken Kok
on 22 May 2022
Commented: Walter Roberson
on 22 May 2022
I have a button group with 2 choices, being Low Pass and High Pass. I want to write the callback function for a button such that when I click on the button, it checks the selection of the button group. I tried to use this but it does not work and says unrecognised function or variable 'value'
% Button pushed function: STARTButton
function STARTButtonPushed(app, event)
selection = app.FilterTypeButtonGroup.SelectedObject;
if selection == 'Low Pass'
value = 1;
elseif selection == 'High Pass'
value = 2;
end
app.SelectionEditField.Value = value;
end
0 Comments
Accepted Answer
Walter Roberson
on 22 May 2022
https://www.mathworks.com/help/matlab/ref/uibuttongroup.html#mw_64460ebb-84cc-4b21-8e3c-1da7ae15c44d
SelectedObject for a uibuttongroup is the handle of the button, not its label.
A button group is not a single object that happens to display multiple buttons. A button group is a collection of buttons, each of which can have its own behavior and label and position controls and whatever.
2 Comments
Walter Roberson
on 22 May 2022
You could set UserData for each button. Or you could set the tag for each button.
Of you could set the String property for each button, after which you could do
selection = app.FilterTypeButtonGroup.SelectedObject.String;
and then you would not need an index for them.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!