Thread Subject: guidata returns empty array on CreateFcn callback?

Subject: guidata returns empty array on CreateFcn callback?

From: Ian Clarkson

Date: 9 May, 2008 15:43:03

Message: 1 of 2

Hello all!

I have a listbox which I'm trying to populate with some
information I'd like to save. The listbox should populate as
soon as the figure shows, so I've added the code within the
CreateFcn callback. The GUIDE skeleton for the function
(MATLAB R12.1) is:

function varargout = listbox_CreateFcn(h, eventdata,
handles, varargin)

The 'handles' variable is empty. When I try to call
guidata(h), it also returns an empty array. guihandles
returns all of the handles in the figure, but when I try to
call guidata to save to any of the handles returned by
guihandles, they don't seem to save so they're accessible by
other callbacks later on. I'm very confused about what
approach to use for GUIs:

1) guidata -- seems you can both save and retrieve, so only
one function is required
2) setappdata/getappdata -- use one or the other to save and
retrieve. Why would this be used above guidata?
3) global variables -- this is another way to store
application data
4) guihandles -- what's the difference between this and
calling guidata with a single argument?

Subject: guidata returns empty array on CreateFcn callback?

From: matt dash

Date: 9 May, 2008 16:15:05

Message: 2 of 2

For all the gui's i've made, I've never used the createfcn's
(since the "runs during object creation" is a little too
ambiguous for my tastes).... But it sounds like you can
instead modify the the gui opening function to do exactly
what you need.

As for the whole guidata business... I've made some really
complicated gui's and I've never needed any command besides
guidata. A few things to remember:

If you are calling a function (for example, a callback) that
uses "handles" within another function call guidata before
(to save) and after (to reload):

function outerfunction(hObject,evetdata,handles)
...
guidata(gcf,handles)
myfunction(handles)
handles=guidata(gcf)
...
%more lines
%resave at end of function:
guidata(gcf,handles)



Always remember to save handles at the end of your functions:

guidata(gcf,handles)


In general I also get better results by ONLY using guidata
to save/load handles, as opposed to ever having handles as
an input or output of a function (like guide does).



Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
guidata guihandles setappdata getappdata gui Ian Clarkson 9 May, 2008 11:47:08
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com