Path: news.mathworks.com!not-for-mail
From: "matt dash" <md222@mail.gatech.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: gui problem
Date: Wed, 16 Apr 2008 17:09:46 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 64
Message-ID: <fu5bsq$4mb$1@fred.mathworks.com>
References: <fu0llq$iu6$1@fred.mathworks.com> <fu5a5l$mhj$1@fred.mathworks.com>
Reply-To: "matt dash" <md222@mail.gatech.edu>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1208365786 4811 172.30.248.38 (16 Apr 2008 17:09:46 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 16 Apr 2008 17:09:46 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 939004
Xref: news.mathworks.com comp.soft-sys.matlab:463373


OK, the problem is obvious now. 

Since you used GUIDE to make the gui, the guidata command
should only be used to store the variable "handles". Calling
the guidata command again with something like
guidata(hObject,timeplot5) will completely overwrite your
handles structure, which is a very bad thing. 

Now, when you run the callback to listbox1, the graph1
callback hasnt necessarily run yet, and so the line:
guidata(hObject,timeplot5) hasn't run, so guidata still
contains the handles variable (which is a structure) since
this is the default setting (see the line
guidata(hObject,handles) at the end of the gui_openingfcn)

so, in listbox1callback, the line timeplot5=guidata(hObject)
is just storing the handles structure under the new name
timeplot5. and your set line actually looks like:
set(handles.listbox1,'string',handles) which is what is
causing the error.

How can you fix it?

In general, you dont want to use guidata to try to store
variables like that. Instead, just trust the fact that guide
(by default) keeps the handles structure current between all
callbacks in the gui. So the easiest way to pass a variable
between two functions is to put it in the handles structure,
and let guide handle the rest. To do this, simply preface
the variable name with the word handles. instead of
timeplot5, always write it as "handles.timeplot5" (without
the quotes) and everying will be ok. 

In short, until you learn enough to figure out more elegant
solutions, you can preface EVERY variable in a gui with
"handles." and things will usually work out the way you want
them to. 


One more warning though: the fig file you sent me has the
graph saved as part of the fig file, which means graph
callback doesnt actually run when you load the gui. It might
 be a better idea to just run the graph callback as part of
the opening function (add the line 
Graph1_Callback(hObject, [], handles
to the VERY END of the opening function)
This will ensure that the handles.timeplot5 variable gets
created before the user has a chance to click any callbacks
that rely on it.

Good luck!