Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Handles
Date: Fri, 12 Dec 2008 04:51:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 29
Message-ID: <ghsqjm$ilc$1@fred.mathworks.com>
References: <ghpjqu$7jn$1@fred.mathworks.com> <ghrd59$9vb$1@fred.mathworks.com> <ghsdje$8fo$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1229057462 19116 172.30.248.38 (12 Dec 2008 04:51:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 12 Dec 2008 04:51:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 939004
Xref: news.mathworks.com comp.soft-sys.matlab:506479



> Hi,
> I think I'm starting to understand this now - your phone number/book analogy really explains it well.
> At the moment I don't mind creating GUIs by coding them directly so I don't need to use the handles structure, however I could see it being very useful if you could create more than one (such as a phone book for business contacts and one for personal contacts - perhaps with some contacts in both?) if this is possible it could be useful, for example pushing button_a sets the 3 drop down menu's in handles_a to value 2 without having to type the set function for each menu.
> Just a thought but I have a feeling its not possible to group widgets in this way.
> 
> Thanks for your advice, and Jiro. The documentation sections are handy, and the video tutorials are always interesting and I always learn something from them.
> 
> As a side question, are there other benifits to creating GUIs in GUIDE other than the speed of drag+drop and positioning? And are there any significant draw-backs to using GUIDE?
> What are people's general preference?
> 
> Cheers,
> Chris


GUIDE or no guide, you won't get very far without using handles. (by which i mean the handles structure as it is called in guide, not the plural of "handle")  I didnt read the whole posts above cause it's late here, but the handles structure is basically just a way to group all your variables (whether they are actual handle(s) or not) into a single variable so that it's easy to pass it around to all your functions. Since they dont all share a common workspace you can just load the handles structure in all your callbacks and they'll all "know the phone numbers" of all the objects in your gui.

basically if you code your gui without guide you'd need to preface all your uicontrol calls with handles:
handles.pushbutton1=uicontrol('style','pushbutton',...)

in guide it does this for you and stores the handle to the object with tag XXX in handles.XXX.

 you can also store any data you want shared between objects in the handles structure, just do handles.data=... or something. basically the handles structure, along with the uicontrols/figure themselves are the only things that persist throughout a gui's life, so anything you don't store in handles will disappear when its function ends. 

After every time you change handles, you need to "save" it with the command guidata(XXX,handles) where XXX is the handle to any uicontrol in your figure (or the handle of the figure itself). this distributes the new phone book to all uicontrols. so make this the last line of any function that adds a new variable to the handles structure. (only need to save it once per function, after all changes have been made)

 But then in every function you still need to load handles as a variable. you could declare it as a third input (all callbacks have two inputs by default), but that gets messy (also you cant just call it "handles", you have to write "guidata(gcbo)" to make sure it loads the new version. if you just write "handles" it'll load whatever version was current when you created the object). Rather than try to change the number of inputs to the callbacks, I find it easier to just make the first line of the callback "handles=guidata(hObject)" where hObject is the first input to the callback. 

if you want opinions on guide/coding, just search for guide, it's a pretty hot topic...