Weird bug in App Designer: " Unrecognized function or variable 'DispNumb'. "
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Simon T
el 5 de Mayo de 2020
Comentada: Steven Lord
el 5 de Mayo de 2020
Hi, I'm using App Designer to create a GUI of a unit converter. There's 14 different converters, ranging from 'metres to feet', to 'Celsius to Fahrenheit', etc. In my App Designer I have a callback that responds to a Convert button being pushed after an input is made. In it are all my conversion calculators, that respond to a user-defined function 'answ = ConverterCore(inp, FromUnit)'. The first few lines are here (the .m file)...
function answ = ConverterCore(inp, FromUnit)
if strcmp(FromUnit, 'C')
answ = (inp*1.8)+32; %C to F
elseif strcmp(FromUnit, 'F')
answ = (inp-32)*(5/9); %F to C
elseif strcmp(FromUnit, 'cm') %Problem from here...
answ = (inp/2.54); %cm to inch
elseif strcmp(FromUnit, 'inches')
answ = (inp*2.54); %inch to cm %...to here
elseif strcmp(FromUnit, 'metres')
answ = (inp/0.3048); %m to ft
.
.
.
end
end
...and the part in my .mlapp file that calls them is here...
When I run the 'cm to inch' part or the 'inch to cm' part, I get this:
Unrecognized function or variable 'DispNumb'.
Error in Milestone_3_GUI/ConvertButtonPushed (line 117)
app.HasbeenconvertedtoEditField.Value = (DispNumb);
(that's all red in my UDF), line 117 is here:
app.HasbeenconvertedtoEditField.Value = (DispNumb);
And remember this code works for all of my converters except for cm to inch and inch to cm, so it's bizarre!
Lastly, if this helps, here's the calls to my UDF for the same parts above:
% Button pushed function: ConvertButton
function ConvertButtonPushed(app, event)
value = app.FromtoDropDown.Value;
if strcmp(value, 'Celsius to Fahrenheit')
DispNumb = ConverterCore(app.ValueEditField_C.Value, 'C');
app.UnitSign.Value = ('˚F');
elseif strcmp(value, 'Fahrenheit to Celsius')
DispNumb = ConverterCore(app.ValueEditField_F.Value, 'F');
app.UnitSign.Value = ('˚C');
elseif strcmp(value, 'Centimetres to Inches')
DispNumb = ConverterCore(app.ValueEditField_DistnMass.Value, 'cm');
app.UnitSign.Value = ('inches');
elseif strcmp(value, 'Inches to Centimetres')
DispNumb = ConverterCore(app.ValueEditField_DistnMass.Value, 'inches');
app.UnitSign.Value = ('cm');
elseif strcmp(value, 'Metres to Feet')
DispNumb = ConverterCore(app.ValueEditField_DistnMass.Value, 'metres');
.
.
.
end
end
I see no difference! I really need some guidance on what to do.
Cheers! Let me know if there's any lines I can give to clarify anything.
5 comentarios
Steven Lord
el 5 de Mayo de 2020
Alternately instead of an if / elseif / else / end block or a switch / case / otherwise / end block you could create a cell array of function handles, one per element of your dropdown, where each function performs the appropriate conversion for that item in your dropdown. Use ismember to identify which element of the Items property is captured in the Value property and call the appropriate function handle from the cell array.
You would need to keep the Items of your dropdown list and the function handles in sync, but that's not much different from needing to keep the Items of your dropdown list and the elements in your if or switch statements in sync.
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Descriptive Statistics and Visualization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!