Undefined function or variable (Passing data between functions)
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I got this problem. When storing data in a function and then I trying to retrieve it 'Undefined function or variable 'GI'' occurs.
This is the code in which I get the data from a GUI (It works well):
function [GI]=GUI_INP(hObject, eventdata)
%Get the handle of Input_parameters and Geometrical_characteristics
hfig_i_p = findobj('Tag','Initial_parameters');
%If exists (not empty)
if ~isempty(hfig_i_p)
i_p=guidata(hfig_i_p);
%ТТХ
GI.Vpol=i_p.Vpol_value;
%Полетные параметры
GI.plotn=i_p.plotn_value; %плотность воздуха
else
disp('INGRESE LOS DATOS EN I_P Y G_C');
end
end
And then the code in which I try to retrieve that data:
function [sys,Inp,geom_aircraft]=Z_INP(GI)
%ТТХ
Inp.Vpol=GI.Vpol;
%полетные параметры
Inp.plotn=GI.plotn; %плотность воздуха
end
I will aprecciate the help.
5 commentaires
Réponses (1)
Jan
le 22 Mai 2018
Modifié(e) : Jan
le 22 Mai 2018
How do you call these functions?
GI = GUI_INP(hObject, eventdata);
[sys,Inp,geom_aircraft] = Z_INP(GI);
This should work. At least partially, because sys and geom_aircraft are still undefined.
The code will fail, when the wanted figure is not found. Better use error() with a clear message, instead of just a disp(), because the following code will fail with confusing messages.
If you have a lot of open figures containing many objects, this
hfig_i_p = findobj('Tag','Initial_parameters');
will take some time, because it compares the Tags of all GUI-elements. Specify the object type instead:
hfig_i_p = findobj(allchild(groot), 'flat', 'Tag', 'Initial_parameters', 'Type', 'Figure');
Currently this is redundant, because the children of groot are figures only. But maybe this will change in the future.
2 commentaires
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!