Index value for button group

조회 수: 14 (최근 30일)
Ye Ken Kok
Ye Ken Kok 2022년 5월 22일
댓글: Walter Roberson 2022년 5월 22일
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

채택된 답변

Walter Roberson
Walter Roberson 2022년 5월 22일
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
Ye Ken Kok
Ye Ken Kok 2022년 5월 22일
So if I want to give each button like an index number, what should I do?
Walter Roberson
Walter Roberson 2022년 5월 22일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by