Borrar filtros
Borrar filtros

Function output does not get recocnized

1 visualización (últimos 30 días)
Marlon
Marlon el 14 de Oct. de 2023
Comentada: Image Analyst el 14 de Oct. de 2023
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

Respuestas (2)

Marlon
Marlon el 14 de Oct. de 2023
Movida: Stephen23 el 14 de Oct. de 2023
I found the way:
function func3(app)
[u,v,x] = DropdownValueChanged(app);
e=u+v+x;
app.EditField2.Value=e;
end
  1 comentario
Image Analyst
Image Analyst el 14 de Oct. de 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).

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 14 de Oct. de 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.

Categorías

Más información sobre Time Series Collections en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by