<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240818</link>
    <title>MATLAB Central Newsreader - Handles</title>
    <description>Feed for thread: Handles</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 10 Dec 2008 23:37:02 -0500</pubDate>
      <title>Handles</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240818#616298</link>
      <author>Chris </author>
      <description>Hi all,&lt;br&gt;
I've been trying to learn about the 'handles' thing that appears in GUIDE scripts I've downloaded and in scripts I've downloaded from here. I just can't seem to get my head around it.&lt;br&gt;
I have uploaded an example of my script where I haven't used this at all but it needs to be reviewed - I'll add the link when it becomes available.&lt;br&gt;
&lt;br&gt;
However, in the meantime, an example of a function nested within my GUI is:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;m3=uicontrol(fig,...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'style','pop');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;function calcbutton(source,eventdata); %push to calculate button&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;str3=get(m3,'string');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;val3=get(m3,'value');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&lt;br&gt;
I assume, using handles provides benifits which aren't apparent at the moment. Any advice on where to use this or where to research it would be greatly appreciated.&lt;br&gt;
&lt;br&gt;
An example of the code I'm struggling to understand:&lt;br&gt;
function pushbutton1_Callback(hObject, eventdata, handles)&lt;br&gt;
% hObject    handle to pushbutton1 (see GCBO)&lt;br&gt;
% eventdata  reserved - to be defined in a future version of MATLAB&lt;br&gt;
% handles    structure with handles and user data (see GUIDATA)&lt;br&gt;
saveState(handles)&lt;br&gt;
&lt;br&gt;
I have read the help files on GUIDATA and GUIHANDLES but still don't understand it I'm afraid.&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
Chris</description>
    </item>
    <item>
      <pubDate>Thu, 11 Dec 2008 03:05:05 -0500</pubDate>
      <title>Re: Handles</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240818#616317</link>
      <author>Jiro Doke</author>
      <description>&quot;Chris &quot; &amp;lt;chris.crawshaw@gmail.com&amp;gt; wrote in message &amp;lt;ghpjqu$7jn$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi all,&lt;br&gt;
&amp;gt; I've been trying to learn about the 'handles' thing that appears in GUIDE scripts I've downloaded and in scripts I've downloaded from here. I just can't seem to get my head around it.&lt;br&gt;
&amp;gt; I have uploaded an example of my script where I haven't used this at all but it needs to be reviewed - I'll add the link when it becomes available.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; However, in the meantime, an example of a function nested within my GUI is:&lt;br&gt;
&amp;gt;     m3=uicontrol(fig,...&lt;br&gt;
&amp;gt;         'style','pop');&lt;br&gt;
&amp;gt;     function calcbutton(source,eventdata); %push to calculate button&lt;br&gt;
&amp;gt;         str3=get(m3,'string');&lt;br&gt;
&amp;gt;         val3=get(m3,'value');&lt;br&gt;
&amp;gt;     end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I assume, using handles provides benifits which aren't apparent at the moment. Any advice on where to use this or where to research it would be greatly appreciated.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; An example of the code I'm struggling to understand:&lt;br&gt;
&amp;gt; function pushbutton1_Callback(hObject, eventdata, handles)&lt;br&gt;
&amp;gt; % hObject    handle to pushbutton1 (see GCBO)&lt;br&gt;
&amp;gt; % eventdata  reserved - to be defined in a future version of MATLAB&lt;br&gt;
&amp;gt; % handles    structure with handles and user data (see GUIDATA)&lt;br&gt;
&amp;gt; saveState(handles)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have read the help files on GUIDATA and GUIHANDLES but still don't understand it I'm afraid.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Cheers,&lt;br&gt;
&amp;gt; Chris&lt;br&gt;
&lt;br&gt;
Chris,&lt;br&gt;
&lt;br&gt;
Is it okay to assume that you read through the &quot;Creating GUIs with GUIDE&quot; section of the documentation?&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/bqz6p81.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/bqz6p81.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
The above page is also found by typing the following in the Command Window:&lt;br&gt;
&lt;br&gt;
web([docroot,'/techdoc/creating_guis/bqz6p81.html'])&lt;br&gt;
&lt;br&gt;
One thing to note is that GUIDE-generated files don't use Nested Functions, so mixing them inside may have some adverse effects. &quot;handles&quot; variable is used to give user the access to various graphics components in your GUI, and it allows you to change and set properties. You can store user data to &quot;handles&quot;, and you can use GUIDATA to update &quot;handles&quot; so that other GUI components in your GUI will have access to it.&lt;br&gt;
&lt;br&gt;
I suggest you take a look at some of the videos here:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://blogs.mathworks.com/videos/category/gui-or-guide/&quot;&gt;http://blogs.mathworks.com/videos/category/gui-or-guide/&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
The two videos at the end may give you the basics to help you get your head around the concepts.&lt;br&gt;
&lt;br&gt;
jiro</description>
    </item>
    <item>
      <pubDate>Thu, 11 Dec 2008 15:55:20 -0500</pubDate>
      <title>Re: Handles</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240818#616425</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Chris &quot; &amp;lt;chris.crawshaw@gmail.com&amp;gt; wrote in message &lt;br&gt;
news:ghpjqu$7jn$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Hi all,&lt;br&gt;
&amp;gt; I've been trying to learn about the 'handles' thing that appears in GUIDE &lt;br&gt;
&amp;gt; scripts I've downloaded and in scripts I've downloaded from here. I just &lt;br&gt;
&amp;gt; can't seem to get my head around it.&lt;br&gt;
&amp;gt; I have uploaded an example of my script where I haven't used this at all &lt;br&gt;
&amp;gt; but it needs to be reviewed - I'll add the link when it becomes available.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; However, in the meantime, an example of a function nested within my GUI &lt;br&gt;
&amp;gt; is:&lt;br&gt;
&amp;gt;    m3=uicontrol(fig,...&lt;br&gt;
&amp;gt;        'style','pop');&lt;br&gt;
&amp;gt;    function calcbutton(source,eventdata); %push to calculate button&lt;br&gt;
&amp;gt;        str3=get(m3,'string');&lt;br&gt;
&amp;gt;        val3=get(m3,'value');&lt;br&gt;
&amp;gt;    end&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I assume, using handles provides benifits which aren't apparent at the &lt;br&gt;
&amp;gt; moment. Any advice on where to use this or where to research it would be &lt;br&gt;
&amp;gt; greatly appreciated.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; An example of the code I'm struggling to understand:&lt;br&gt;
&amp;gt; function pushbutton1_Callback(hObject, eventdata, handles)&lt;br&gt;
&amp;gt; % hObject    handle to pushbutton1 (see GCBO)&lt;br&gt;
&amp;gt; % eventdata  reserved - to be defined in a future version of MATLAB&lt;br&gt;
&amp;gt; % handles    structure with handles and user data (see GUIDATA)&lt;br&gt;
&amp;gt; saveState(handles)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have read the help files on GUIDATA and GUIHANDLES but still don't &lt;br&gt;
&amp;gt; understand it I'm afraid.&lt;br&gt;
&lt;br&gt;
Don't worry about GUIDATA and GUIHANDLES for right now.  First, have you &lt;br&gt;
read the section in the Getting Started guide that deals with Handle &lt;br&gt;
Graphics objects?&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f3-15974.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f3-15974.html&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
One metaphor that I find useful is to think of an object's handle as its &lt;br&gt;
telephone number.  Using the handle/phone number, you can communicate with &lt;br&gt;
the object using either GET (which allows you to ask the object questions, &lt;br&gt;
like &quot;What is your Position property?&quot;) or SET (which allows you to give the &lt;br&gt;
object an order, like &quot;Change your Position property to this vector.&quot;).&lt;br&gt;
&lt;br&gt;
The way GUIDE defines the callback functions for the objects, it passes in a &lt;br&gt;
handles structure (a telephone book) listing the handles for all the objects &lt;br&gt;
in the GUI.  Just like a phone book, a handles structure makes it easier to &lt;br&gt;
find an object's handle/phone number.  As the comment says, the handles &lt;br&gt;
structure not only contains handles to objects, but it can also contain user &lt;br&gt;
data (like a note you write inside the phone book.)&lt;br&gt;
&lt;br&gt;
If you don't have a copy of the handles structure/phone book in your &lt;br&gt;
function, you can retrieve one with GUIDATA or GUIHANDLES, and if you want &lt;br&gt;
to copy the additional data/notes you've made in your local copy of the &lt;br&gt;
handles structure to the main handles structure that the figure keeps for &lt;br&gt;
its reference, you can also use GUIDATA and GUIHANDLES for that purpose.&lt;br&gt;
&lt;br&gt;
It's not a perfect metaphor (for instance, you can change your telephone &lt;br&gt;
number but you can't really change an object's handle) but as metaphors go, &lt;br&gt;
it's not half bad if I do say so myself.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
    <item>
      <pubDate>Fri, 12 Dec 2008 01:09:02 -0500</pubDate>
      <title>Re: Handles</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240818#616530</link>
      <author>Chris </author>
      <description>&quot;Steven Lord&quot; &amp;lt;slord@mathworks.com&amp;gt; wrote in message &amp;lt;ghrd59$9vb$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &quot;Chris &quot; &amp;lt;chris.crawshaw@gmail.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt; news:ghpjqu$7jn$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; &amp;gt; Hi all,&lt;br&gt;
&amp;gt; &amp;gt; I've been trying to learn about the 'handles' thing that appears in GUIDE &lt;br&gt;
&amp;gt; &amp;gt; scripts I've downloaded and in scripts I've downloaded from here. I just &lt;br&gt;
&amp;gt; &amp;gt; can't seem to get my head around it.&lt;br&gt;
&amp;gt; &amp;gt; I have uploaded an example of my script where I haven't used this at all &lt;br&gt;
&amp;gt; &amp;gt; but it needs to be reviewed - I'll add the link when it becomes available.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; However, in the meantime, an example of a function nested within my GUI &lt;br&gt;
&amp;gt; &amp;gt; is:&lt;br&gt;
&amp;gt; &amp;gt;    m3=uicontrol(fig,...&lt;br&gt;
&amp;gt; &amp;gt;        'style','pop');&lt;br&gt;
&amp;gt; &amp;gt;    function calcbutton(source,eventdata); %push to calculate button&lt;br&gt;
&amp;gt; &amp;gt;        str3=get(m3,'string');&lt;br&gt;
&amp;gt; &amp;gt;        val3=get(m3,'value');&lt;br&gt;
&amp;gt; &amp;gt;    end&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I assume, using handles provides benifits which aren't apparent at the &lt;br&gt;
&amp;gt; &amp;gt; moment. Any advice on where to use this or where to research it would be &lt;br&gt;
&amp;gt; &amp;gt; greatly appreciated.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; An example of the code I'm struggling to understand:&lt;br&gt;
&amp;gt; &amp;gt; function pushbutton1_Callback(hObject, eventdata, handles)&lt;br&gt;
&amp;gt; &amp;gt; % hObject    handle to pushbutton1 (see GCBO)&lt;br&gt;
&amp;gt; &amp;gt; % eventdata  reserved - to be defined in a future version of MATLAB&lt;br&gt;
&amp;gt; &amp;gt; % handles    structure with handles and user data (see GUIDATA)&lt;br&gt;
&amp;gt; &amp;gt; saveState(handles)&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I have read the help files on GUIDATA and GUIHANDLES but still don't &lt;br&gt;
&amp;gt; &amp;gt; understand it I'm afraid.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Don't worry about GUIDATA and GUIHANDLES for right now.  First, have you &lt;br&gt;
&amp;gt; read the section in the Getting Started guide that deals with Handle &lt;br&gt;
&amp;gt; Graphics objects?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f3-15974.html&quot;&gt;http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f3-15974.html&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; One metaphor that I find useful is to think of an object's handle as its &lt;br&gt;
&amp;gt; telephone number.  Using the handle/phone number, you can communicate with &lt;br&gt;
&amp;gt; the object using either GET (which allows you to ask the object questions, &lt;br&gt;
&amp;gt; like &quot;What is your Position property?&quot;) or SET (which allows you to give the &lt;br&gt;
&amp;gt; object an order, like &quot;Change your Position property to this vector.&quot;).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The way GUIDE defines the callback functions for the objects, it passes in a &lt;br&gt;
&amp;gt; handles structure (a telephone book) listing the handles for all the objects &lt;br&gt;
&amp;gt; in the GUI.  Just like a phone book, a handles structure makes it easier to &lt;br&gt;
&amp;gt; find an object's handle/phone number.  As the comment says, the handles &lt;br&gt;
&amp;gt; structure not only contains handles to objects, but it can also contain user &lt;br&gt;
&amp;gt; data (like a note you write inside the phone book.)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you don't have a copy of the handles structure/phone book in your &lt;br&gt;
&amp;gt; function, you can retrieve one with GUIDATA or GUIHANDLES, and if you want &lt;br&gt;
&amp;gt; to copy the additional data/notes you've made in your local copy of the &lt;br&gt;
&amp;gt; handles structure to the main handles structure that the figure keeps for &lt;br&gt;
&amp;gt; its reference, you can also use GUIDATA and GUIHANDLES for that purpose.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; It's not a perfect metaphor (for instance, you can change your telephone &lt;br&gt;
&amp;gt; number but you can't really change an object's handle) but as metaphors go, &lt;br&gt;
&amp;gt; it's not half bad if I do say so myself.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -- &lt;br&gt;
&amp;gt; Steve Lord&lt;br&gt;
&amp;gt; slord@mathworks.com &lt;br&gt;
&amp;gt; &lt;br&gt;
Hi,&lt;br&gt;
I think I'm starting to understand this now - your phone number/book analogy really explains it well.&lt;br&gt;
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.&lt;br&gt;
Just a thought but I have a feeling its not possible to group widgets in this way.&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
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?&lt;br&gt;
What are people's general preference?&lt;br&gt;
&lt;br&gt;
Cheers,&lt;br&gt;
Chris</description>
    </item>
    <item>
      <pubDate>Fri, 12 Dec 2008 04:51:02 -0500</pubDate>
      <title>Re: Handles</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240818#616544</link>
      <author>matt dash</author>
      <description>&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I think I'm starting to understand this now - your phone number/book analogy really explains it well.&lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; Just a thought but I have a feeling its not possible to group widgets in this way.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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?&lt;br&gt;
&amp;gt; What are people's general preference?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Cheers,&lt;br&gt;
&amp;gt; Chris&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
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 &quot;handle&quot;)  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 &quot;know the phone numbers&quot; of all the objects in your gui.&lt;br&gt;
&lt;br&gt;
basically if you code your gui without guide you'd need to preface all your uicontrol calls with handles:&lt;br&gt;
handles.pushbutton1=uicontrol('style','pushbutton',...)&lt;br&gt;
&lt;br&gt;
in guide it does this for you and stores the handle to the object with tag XXX in handles.XXX.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;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. &lt;br&gt;
&lt;br&gt;
After every time you change handles, you need to &quot;save&quot; 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)&lt;br&gt;
&lt;br&gt;
&amp;nbsp;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 &quot;handles&quot;, you have to write &quot;guidata(gcbo)&quot; to make sure it loads the new version. if you just write &quot;handles&quot; 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 &quot;handles=guidata(hObject)&quot; where hObject is the first input to the callback. &lt;br&gt;
&lt;br&gt;
if you want opinions on guide/coding, just search for guide, it's a pretty hot topic... </description>
    </item>
  </channel>
</rss>

