필터 지우기
필터 지우기

Function output does not get recocnized

조회 수: 1 (최근 30일)
Marlon
Marlon 2023년 10월 14일
댓글: Image Analyst 2023년 10월 14일
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
Marlon 2023년 10월 14일
이동: Stephen23 2023년 10월 14일
I found the way:
function func3(app)
[u,v,x] = DropdownValueChanged(app);
e=u+v+x;
app.EditField2.Value=e;
end
  댓글 수: 1
Image Analyst
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
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.

카테고리

Help CenterFile Exchange에서 Time Series Collections에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by