GUI handles problem... throughout code it vanishes!?

12 visualizzazioni (ultimi 30 giorni)
Hello,
I'm making GUI throught GUIDE and have a little problem in my code.
I'm using handles to pass variables between callback functions. The problem is two handles which I store in edit text fields. After storing to workspace I've filled handles like..
handles.LAIi=LAIi (% my variable)
at the end of callback fnc of editfield I did check existence of LAI=XXX in handles.
...
mer_data: [436x24 double] % CHECK AFTER editbox CALLBACK
FileName_data: '0_VRT_DOMANIN_110211.xls'
LAIi: 16
But later in code in other function I'need to use that value. So i call it by handles.LAIi
rs=1/((gl*0.002/0.08)*((handles.LAIi)/2));
handles.rs=rs;
assignin('base','rs',rs);
Matlab halts with error
mer_data: [436x24 double] % THIS IS CHECK before that equation
FileName_data: '0_VRT_DOMANIN_110211.xls'
T_z: [436x1 double] % AND THE LAIi is GONE!! :\
T_zp: [436x1 double]
L: [436x1 double]
Ez: [436x1 double]
Ezp: [436x1 double]
Rh_z: [436x1 double]
ez: [436x1 double]
Rh_zp: [436x1 double]
ezp: [436x1 double]
gl: 0.2000
??? Reference to non-existent field 'LAIi'.
Error in ==> GUI>vypocti_Callback at 286
rs=1/((gl*0.002/0.08)*((handles.LAIi)/2)); %
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> GUI at 39
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)GUI('vypocti_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
HELP PLEASE.. POST your advices! Need that to be done :\ and I cannot see where's problem since i'm using variable mer_data same way with no problem...

Risposta accettata

Matt Fig
Matt Fig il 13 Giu 2011
GUIDATA does not update the handles structure, but stores the handles structure in the figure's applicationdata. The handles structure is only for storing the handles to all of the uicontrols in the figure.
To store data for use between callbacks, use GUIDATA. In your callbacks, do this:
G = guidata(gcbf); % Get the applicationdata.
G.new = 9; % Add data to the structure, when needed.
guidata(gcbf,G) % Store the structure for later use...
Now in any other callback, calling the first line will get you the structure which includes the new data. Use this method to pass data around between callbacks.
  1 Commento
Lex
Lex il 14 Giu 2011
Two answers - replyies from Matt that pushed me forward
Thank you Matt you're my hero :D

Accedi per commentare.

Più risposte (1)

Paulo Silva
Paulo Silva il 13 Giu 2011
When you do
handles.LAIi=LAIi;
you must also update the handles structure
guidata(hObject, handles);
  1 Commento
Lex
Lex il 13 Giu 2011
I did insert guidata statement after handles.LAIi statment.. but there's no difference :\
Thank you for your answer!

Accedi per commentare.

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by