Issue with Switch state in AppDesigner

조회 수: 30 (최근 30일)
Jason
Jason 2020년 1월 16일
댓글: Cameron B 2020년 1월 16일
Hello, I am migrating from GUIDE to Appdesigner and can't understand why Im getting an error
I have a switch that I want to change the color of a lamp component:
% Value changed function: VioletSwitch
function VioletSwitchValueChanged(app, event)
value = app.VioletSwitch.Value
if value=='On'
app.Lamp_V.Color='#b700ff';
else
app.Lamp_V.Color='r';
end
This works when the switch is on, but not when the switch is off, I get the following error message which I dont understand
value =
'Off'
Matrix dimensions must agree.
Error in Spectrometer/VioletSwitchValueChanged (line 174)
if value=='On'

답변 (1개)

Cameron B
Cameron B 2020년 1월 16일
편집: Cameron B 2020년 1월 16일
function VioletSwitchValueChanged(app, event)
value = app.VioletSwitch.Value
if strcmpi(value,'On') == 1
app.Lamp_V.Color='g';
else
app.Lamp_V.Color='r';
end
  댓글 수: 2
Jason
Jason 2020년 1월 16일
Thankyou, I've also found switch works, but I'd like t find out why the if else doesnt work
Cameron B
Cameron B 2020년 1월 16일
Yes, switch might be a better option for this. I edited my original response and replaced 'b700ff' with 'g'

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by