Undefined function or variable (Passing data between functions)

조회 수: 1 (최근 30일)
Oscar Espinosa
Oscar Espinosa 2018년 5월 22일
댓글: Oscar Espinosa 2018년 5월 22일
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
Oscar Espinosa
Oscar Espinosa 2018년 5월 22일
편집: Oscar Espinosa 2018년 5월 22일
Is in the workspace while function executing, then just return ans with the values Vpol and plotn. If I try executing in the Command Window I got 'Undefined function or variable 'hObject''.
Oscar Espinosa
Oscar Espinosa 2018년 5월 22일
Thank for help, I found the problem. The function do not need hObject and eventdata.
function [GI]=GUI_INP(hObject, eventdata)

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2018년 5월 22일
편집: Jan 2018년 5월 22일
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
Oscar Espinosa
Oscar Espinosa 2018년 5월 22일
Actually I'm calling
[sys,Inp,geom_aircraft] = Z_INP(GI);
from another funtion. I'm doing this intermediate step between the data stored in a GUI and the function that needs that data because the function to execute have 8 input, and if I add the hObject, and evenData as 2 more arguments it just does not work.
This is the function which is calling:
function [Result,Inp,lz,nu,str,c_,f0,fk]=m(s_lz,s_nu,s_srt,s_ak,s_c,s_c_k_koef,s_f0,s_fk);
[lz,nu,str,ak,c_,c_k_koef,f0,fk]=INP(s_lz,s_nu,s_srt,s_ak,s_c,s_c_k_koef,s_f0,s_fk);
shet=1;
for s=1:length(lz)
Inp.lz=lz(shet,1);
Inp.nu=nu(shet,1);
Inp.str=str(shet,1);
Inp.a_k=ak(shet,1);
Inp.c_=c_(shet,1);
Inp.c_k_koef=c_k_koef(shet,1);
Inp.f_0=f0(shet,1);
Inp.f_k=fk(shet,1);
[sys,Inp,geom_aircraft]=Z_INP(GI);
...
end
Oscar Espinosa
Oscar Espinosa 2018년 5월 22일
Thank you by the help, I found the problem, posted it lines above. And I will keep in mind the advices that you gave me.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by