Function output does not get recocnized
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi guys,
in the following the example code of an Matlab App I'm trying to figure out.
When an option gets selected in the pushdown menu, the edit fields should get a defined value (already working). When I push the start Button, the variable e should get calculated with selected values in another function and displayed in an editfield.
The problem is, I get the error message "Unrecognized function or variable 'u'." when I press start. Maybe somebody could help me with this?
methods (Access = private)
function [u,v,x] = DropdownValueChanged(app, event)
selectedOption = app.DropDown.Value;
% Abhängig von der ausgewählten Option die EditField-Werte aktualisieren
if strcmp(selectedOption, 'Option 1')
app.EditField.Value = 2;
app.EditField_2.Value = 3;
app.EditField_3.Value = 5;
elseif strcmp(selectedOption, 'Option 2')
app.EditField.Value = 0;
app.EditField_2.Value = 0;
app.EditField_3.Value = 0;
end
u=app.EditField.Value;
v=app.EditField_2.Value;
x=app.EditField_3.Value;
end
function func3(app,u,v,x)
e=u+v+x;
app.EditField2.Value=e;
end
end
callbacks:
% Callbacks that handle component events
methods (Access = private)
% Value changed function: DropDown
function DropDownValueChanged(app, event)
value = app.DropDown.Value;
end
% Value changed function: EditField
function EditFieldValueChanged(app, event)
value = app.EditField.Value;
end
% Value changed function: EditField_2
function EditField_2ValueChanged(app, event)
value = app.EditField_2.Value;
end
% Value changed function: EditField_3
function EditField_3ValueChanged(app, event)
value = app.EditField_3.Value;
end
% Value changed function: EditField2
function EditField2ValueChanged(app, event)
value = app.EditField2.Value;
end
% Value changed function: StartButton
function StartButtonValueChanged(app, event)
DropdownValueChanged(app, event)
func3(u,v,x)
end
% Clicked callback: DropDown
function DropDownClicked(app, event)
item = event.InteractionInformation.Item;
DropdownValueChanged(app, event)
end
Antworten (2)
Marlon
am 14 Okt. 2023
Verschoben: Stephen23
am 14 Okt. 2023
1 Kommentar
Image Analyst
am 14 Okt. 2023
I'm not sure why you have two DropdownValueChanged functions. This one:
function [u,v,x] = DropdownValueChanged(app, event)
selectedOption = app.DropDown.Value;
% Abhängig von der ausgewählten Option die EditField-Werte aktualisieren
if strcmp(selectedOption, 'Option 1')
app.EditField.Value = 2;
app.EditField_2.Value = 3;
app.EditField_3.Value = 5;
elseif strcmp(selectedOption, 'Option 2')
app.EditField.Value = 0;
app.EditField_2.Value = 0;
app.EditField_3.Value = 0;
end
u=app.EditField.Value;
v=app.EditField_2.Value;
x=app.EditField_3.Value;
end
and this one
% Value changed function: DropDown
function DropDownValueChanged(app, event)
value = app.DropDown.Value;
end
Anyway, I hope my answer let you realize that you needed to get u, v, and x before calling func3(). Your first version of DropdownValueChanged will give you those values if you accept them (as you did now in your answer).
Image Analyst
am 14 Okt. 2023
When you click Start, this code runs:
% Value changed function: StartButton
function StartButtonValueChanged(app, event)
DropdownValueChanged(app, event)
func3(u,v,x)
end
Variables are not global unless attached to the app structure, or you declare them global. So inside that function, it has no idea what u, v, and x are because you never defined them in that function. If they were defined somewhere else, then you need to get them into that function, like make them fields of the app variable or assign them some values right there in that function.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!