Proper if/else statement in appdesigner

조회 수: 23 (최근 30일)
Tudor Miron
Tudor Miron 2022년 10월 14일
이동: Voss 2022년 10월 14일
In app designer I would like to setup an if/else function that will control the lamp color. I want a value to be within 5% of control value to activate a lamp. I’m trying the below statement but it doesn’t seem to work even when values are exactly the same.
if app.rr_camber_ref.Value >= app.rr_camber.Value*0.95 && app.rr_camber_ref.Value <=app.rr_camber.Value*1.05
app.Lamp_rr_camber.Color='g';
else...
Can someone suggest what would be proper condition statement in this case?
Thank you,
Ted
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2022년 10월 14일
What components are you using for app.rr_camber_ref and app.rr_camber? What are typical values for each?
Tudor Miron
Tudor Miron 2022년 10월 14일
편집: Tudor Miron 2022년 10월 14일
I'm in a process of creating a simple app to aid in static setup of race vehicle (multibody model). Setup parameters of interest are dispayed in gui and I created additional displays for this setup parameters where I can save current values as reference of baseline setup. If I change some setting (front camber for example) I wanted to see which of the rest of setup parameters changed simultaneously (and lots of them do) and require resetting to baseline values so that I test that camber change only rather than multitude of other unintended setup changes. Green lamp will indicate if value of setup parameter is within prescribed tolerance of baseline setup parameter.
5% was just an arbitrary number that I used for my question.
Jan’s suggestion to assign values to variables and use those variables in IF/ELSE statement worked perfectly.

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

채택된 답변

Jan
Jan 2022년 10월 14일
Ref = app.rr_camber_ref.Value;
Value = app.rr_camber.Value;
if abs(Value - Ref) / abs(Ref) < 0.05
app.Lamp_rr_camber.Color='g';
  댓글 수: 2
Tudor Miron
Tudor Miron 2022년 10월 14일
이동: Voss 2022년 10월 14일
Thanks Jan,
Assigning relevant values to a variable and than using this variables in IF/ELSE statement worked just fine.
Thank you!
Ted
Walter Roberson
Walter Roberson 2022년 10월 14일
이동: Voss 2022년 10월 14일
I suspect it was more the difference in how the test was calculated, not so much the fact that variables were assigned to.

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

추가 답변 (0개)

카테고리

Help CenterFile 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!

Translated by