How to create a callback for radio buttons
42 ビュー (過去 30 日間)
古いコメントを表示
I have a group of radio buttons with 3 choices (app.mode1, app.mode2, and app.mode3) in app-designer. When a user clicks one of the radio buttons, I want the name of a separate button to be changed to something else. For example: mode 1: "load", mode 2: "plot", mode 3: "display". I'm able to create a call back for the group of radio buttons as below:
function modeSelectionChanged(app, event)
selectedButton = app.mode.SelectedObject;
end
end
But I have no idea as to how to write the following codes. Would someone please help me out?
Many thanks!
0 件のコメント
採用された回答
Cris LaPierre
2021 年 3 月 16 日
編集済み: Cris LaPierre
2021 年 3 月 16 日
Assuming your button has the name app.Button, and your radio buttons are labeled 'Mode1', 'Mode2', and 'Mode3', something like this
% Selection changed function: Mode
function ModeSelectionChanged(app, event)
selectedButton = app.Mode.SelectedObject;
switch selectedButton.Text
case 'Mode1'
app.Button.Text = "Load";
case 'Mode2'
app.Button.Text = "Plot";
case 'Mode3'
app.Button.Text = "Display";
end
end
5 件のコメント
Eric
2024 年 11 月 11 日
Apologies for necromancing the thread. I don't fully understand how the solution involving values works. It is my understanding that selectedButton is a button object. For radio buttons, button.Value is either 0 or 1. My confusion is regarding how selectedButton.Value works in the example since it is now corresponding to the index of the button rather than the Boolean value?
Cris LaPierre
2024 年 11 月 11 日
You are correct. A button can only have a value of 0 or 1. If there are more than 2 butttons, you cannot use value to determine which button has been selected.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!