Unrecognized method, property, or field 'value' for class

Hi everyone,
I am trying to use a switch in Matlab app designer for a uit converter. However when I code the program to change the items in a drop down menu to change when the switch is flipped, i get this message: 'Unrecognized method, property, or field 'value' for class.' I'm not really sure what this means or how to solve it. I have attatched my code file if you would like to look at it and help me out.
thanks in advance!

댓글 수: 1

SAI
SAI 2024년 11월 12일
Unrecognized method, property, or field
'P2ditField_4' for class 'app1'.

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

 채택된 답변

Mohammad Sami
Mohammad Sami 2020년 5월 5일
You are using smaller case for value on line 37. just change to upper case as follows.
conversionvalue = app.conversiontypeDropDown.Value;

댓글 수: 3

Ah I understand now. I changed the value and I am no longer getting that error. However, when I flip the switch the drop box doesnt change. Could you please have a look at it and tell me where I am gong wrong?
thank you.
You have an extra space at the end of "imperial to metric" in the Items property of your switch.
So you're never getting a logical match because when the switch is on "imperial to metric" its actual value is "imperial to metric " with that extra space at the end and thus will never be equal to your hardcoded comparitive value of "imperial to metric".
Instead, I'd propose you try to match the value to the actual Items.
For example, instead of:
function SwitchValueChanged(app, event)
value = app.Switch.Value;
udc = app.conversiontypeDropDown.Value;
if strcmpi(udc, 'temperature') && strcmpi(value, 'imperial to metric')
app.unitsDropDown.Items = {'fahrenheit to celcius'};
end
end
You could consider:
function SwitchValueChanged(app, event)
value = string(app.Switch.Value);
udc = string(app.conversiontypeDropDown.Value);
if udc == "temperature" && value == string(app.Switch.Items(2))
app.unitsDropDown.Items = "fahrenheit to celcius";
end
end
That way you will always be comparing a value to a possible solution rather than a hardcoded string.
I have R2021a version

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

질문:

2020년 5월 5일

댓글:

SAI
2024년 11월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by