Function output does not get recocnized
1 回表示 (過去 30 日間)
古いコメントを表示
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
回答 (2 件)
Marlon
2023 年 10 月 14 日
移動済み: Stephen23
2023 年 10 月 14 日
1 件のコメント
Image Analyst
2023 年 10 月 14 日
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
2023 年 10 月 14 日
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 件のコメント
参考
カテゴリ
Help Center および File 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!