How to get the value of Radio buttons from App Designer

조회 수: 211 (최근 30일)
Leon
Leon 2019년 6월 24일
댓글: Csanád Temesvári 2021년 3월 23일
Here is my radio button:
app.ButtonGroup
  • app.A_button
  • app.B_button
What I want to do is this:
Button A should be the default button. If the button A is stay pushed or the user does not do anything to this group of buttons, my button value should be 10. If Button B is pushed, my overall button value should be 14.
How can I achieve that? Sorry for the basic question. I'm new to app designer.
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2019년 6월 24일
Leon - what do you mean by button value? Is this a value that you use in some sort of calculation?
Leon
Leon 2019년 6월 24일
Yes, it is a value I use for some later calculation.
We can derive these values fomr an if loop, I guess.
If Button A is slected
Val = 10
else
Val = 14
end
My problem is that I do not know how to specify the if sentence.
Thanks

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

채택된 답변

Adam Danz
Adam Danz 2019년 6월 24일
편집: Adam Danz 2019년 6월 24일
The 'Value' property of the radio buttons returns a logical that is true when selected and false otherwise. Here's an example to follow below.
if app.Button1.Value %where "Button1" is the name of the first radio button
Val = 10
elseif app.Button2.Value
Val = 14
else
Val = 0;
end
Another way to do that is to use the 'SelectedObject' property of the ButtonGroup along with a switch-case.
switch app.ButtonGroup.SelectedObject.Text
case 'Button1' %where "Button1" is the name of the first radio button
val = 10;
case 'Button2'
val = 14;
otherwise
val = 0;
end
  댓글 수: 11
Adam Danz
Adam Danz 2021년 3월 22일
> Unable to resolve the name app.Alakzat_2D_ButtonGroup.SelectedObject.Text.
Take a look at your function,
function [] = plot_2D(~)
switch app.Alakzat_2D_ButtonGroup.SelectedObject.Text
It has no inputs.
You have to pass the app variable to it and there should be a warning in AppDesigner on that line of code indicating that you're not passing the app variable, unless this function is outside of AppDesigner.
Csanád Temesvári
Csanád Temesvári 2021년 3월 23일
Thank you so much!
Obviously, I ran into further problems after I fixed that one, but that's just programming :)

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by