Undefined function or variable (Passing data between functions)
이전 댓글 표시
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
Nicola Bombace
2018년 5월 22일
편집: Nicola Bombace
2018년 5월 22일
If you try to run the file Z_INP.m , it will not know about the Variable GI. After you run the GUI gathering of your data simply use
[sys,Inp,geom_aircraft]=Z_INP(GI);
in a command line or a new script that could look like
[GI]=GUI_INP(hObject, eventdata);
[sys,Inp,geom_aircraft]=Z_INP(GI);
Oscar Espinosa
2018년 5월 22일
Nicola Bombace
2018년 5월 22일
편집: Nicola Bombace
2018년 5월 22일
The question would then be if you see the Variable GI in the workspace after you call the GUI_INP function. If the variable is not there is because this condition ~isempty(hfig_i_p) is false.
Oscar Espinosa
2018년 5월 22일
편집: Oscar Espinosa
2018년 5월 22일
Oscar Espinosa
2018년 5월 22일
답변 (1개)
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.
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!