<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Undocumented Matlab &#187; schema.prop</title> <atom:link href="http://undocumentedmatlab.com/blog/tag/schemaprop/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Thu, 17 May 2012 12:01:26 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.1</generator> <item><title>Setting axes tick labels format</title><link>http://undocumentedmatlab.com/blog/setting-axes-tick-labels-format/</link> <comments>http://undocumentedmatlab.com/blog/setting-axes-tick-labels-format/#comments</comments> <pubDate>Wed, 18 Apr 2012 18:00:17 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Listeners]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Listener]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema.prop]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2856</guid> <description><![CDATA[Matlab plot axes ticks can be customized in a way that will automatically update whenever the tick values change.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/axes-looseinset-property/' rel='bookmark' title='Axes LooseInset property'>Axes LooseInset property</a> <small>Matlab plot axes have an undocumented LooseInset property that sets empty margins around the axes, and can be set to provide a tighter fit of the axes to their surroundings....</small></li><li><a
href='http://undocumentedmatlab.com/blog/determining-axes-zoom-state/' rel='bookmark' title='Determining axes zoom state'>Determining axes zoom state</a> <small>The information of whether or not an axes is zoomed or panned can easily be inferred from an internal undocumented object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/fig-files-format/' rel='bookmark' title='FIG files format'>FIG files format</a> <small>FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/customizing-matlab-labels/' rel='bookmark' title='Customizing Matlab labels'>Customizing Matlab labels</a> <small>Matlab's text uicontrol is not very customizable, and does not support HTML or Tex formatting. This article shows how to display HTML labels in Matlab and some undocumented customizations...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Have you ever tried to customize the way in which tick labels appear in Matlab plot axes?</p><p>For example, setting the numerical precision of the labels, or adding some short descriptive text (for example, the units)? If you have, then I bet that you have encountered the following dilemma: Once we modify the tick labels (for discussion sake, let&#8217;s assume the Y axis, so this is done by updating the <b>YTickLabel</b> property), then the corresponding <b>YTickLabelMode</b> property changes from &#8216;auto&#8217; to &#8216;manual&#8217; and loses its relationship to the tick values (<b>YTick</b>). So, if we now zoom or pan the plot, our new labels remain unchanged although the tick values have changed, causing much panic and frustration&#8230; If we also set the tick values manually, this solves <i>that</i> problem but leaves us with another: now, when we zoom or pan, we no longer see any ticks or tick labels at all!</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
src="http://UndocumentedMatlab.com/images/PlotLabels_orig.png" alt="Original plot" title="Original plot" width="134" height="143" /> <img
src="http://UndocumentedMatlab.com/images/PlotLabels_1b.png" alt="Manual labels, auto ticks" title="Manual labels, auto ticks" width="134" height="143" /> <img
src="http://UndocumentedMatlab.com/images/PlotLabels_1c.png" alt="Manual labels, manual ticks" title="Manual labels, manual ticks" width="134" height="143" /><p
class="wp-caption-text">Original plot (left)<br
/>Manual labels, auto ticks (center)<br
/>Manual labels, manual ticks (right)</p></div></center></p><p>Of course, we can always trap the zoom and pan callback functions to update the tick labels dynamically while keeping the tick values automatically. This will work for these cases, but we need to do it separately for zoom and pan. Also, if we modify the axes limits explicitly (via the corresponding <b>YLim</b> property) or indirectly (by modifying the displayed plot data), then the callbacks are not called and the labels are not updated.</p><h3 id="solution">The solution &#8211; using a property change listener</h3><p>A better way to solve this problem is to simply trap changes to the displayed tick values, and whenever these occur to call our dedicated function to update the labels according to the new tick values. This can be done by using UDD, or more precisely the <a
target="_blank" href="http://undocumentedmatlab.com/blog/udd-events-and-listeners/">ability to trap update events on any property</a> (in our case, <b>YTick</b>). Such a mechanism was already <a
target="_blank" href="http://undocumentedmatlab.com/blog/continuous-slider-callback/#Property_Listener">demonstrated here</a> in 2010, as one way to achieve continuous slider feedback. The idea is to use the built-in <i><b>handle.listener</b></i> function with the PropertyPostSet event, as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hhAxes = handle<span style="color: #080;">&#40;</span>hAxes<span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% hAxes is the Matlab handle of our axes</span>
hProp = <span style="color: #0000FF;">findprop</span><span style="color: #080;">&#40;</span>hhAxes,<span style="color:#A020F0;">'YTick'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% a schema.prop object</span>
hListener = <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>hhAxes, hProp, <span style="color:#A020F0;">'PropertyPostSet'</span>, @myCallbackFunction<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">setappdata</span><span style="color: #080;">&#40;</span>hAxes, <span style="color:#A020F0;">'YTickListener'</span>, hListener<span style="color: #080;">&#41;</span>;</pre></div></div><p>Note that we have used <i><b>setappdata</b></i> to store the <code>hListener</code> handle in the axes. This ensures that the listener exists for exactly as long as the axes does. If we had not stored this listener handle somewhere, then Matlab would have immediately deleted the listener hook and our callback function would not have been called upon tick value updates. Forgetting to store listener handles is a common pitfall when using them. If you take a look at the <i><b>addlistener</b></i> function&#8217;s code, you will see that it also uses <i><b>setappdata</b></i> after creating the listener, for exactly this reason. Unfortunately, <i><b>addlistsner</b></i> cannot always be used, and I keep forgetting under which circumstances, so I generally use <i><b>handle.listener</b></i> directly as above: It&#8217;s simple enough to use that I find I never really need to use the simple <i><b>addlistener</b></i> wrapper, but you are welcome to try it yourself.</p><p>That&#8217;s all there is to it: Whenever <b>YTick</b> changes its value(s), our callback function (<i>myCallbackFunction</i>) will automatically be called. It is quite simple to set up. While we cannot use TeX in tick labels yet (this will change in the upcoming <a
target="_blank" href="http://undocumentedmatlab.com/blog/matlab-hg2/">HG2</a>), using <i><b>sprintf</b></i> formatting does enable quite a bit of flexibility in formatting the labels. For example, let&#8217;s say I want my tick labels to have the format &#8216;%.1fV&#8217; (i.e., always one decimal, plus the Volts units):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> myCallbackFunction<span style="color: #080;">&#40;</span>hProp,eventData<span style="color: #080;">&#41;</span>    <span style="color: #228B22;">%#ok - hProp is unused</span>
   hAxes = eventData.<span style="">AffectedObject</span>;
   tickValues = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAxes,<span style="color:#A020F0;">'YTick'</span><span style="color: #080;">&#41;</span>;
   newLabels = arrayfun<span style="color: #080;">&#40;</span>@<span style="color: #080;">&#40;</span>value<span style="color: #080;">&#41;</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">sprintf</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'%.1fV'</span>,value<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>, tickValues, <span style="color:#A020F0;">'UniformOutput'</span>,<span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hAxes, <span style="color:#A020F0;">'YTickLabel'</span>, newLabels<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% myCallbackFunction</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 310px"><img
src="http://UndocumentedMatlab.com/images/PlotLabels_2a.png" alt="Manual labels, automatically updated" title="Manual labels, automatically updated" width="134" height="143" /> <img
src="http://UndocumentedMatlab.com/images/PlotLabels_2b.png" alt="Manual labels, automatically updated" title="Manual labels, automatically updated" width="134" height="143" /><p
class="wp-caption-text">Manual labels, automatically updated</p></div></center></p><h3 id="duplicates">Handling duplicate tick labels</h3><p>Of course, &#8216;%.1fV&#8217; may not be a good format when we zoom in to such a degree that the values differ by less than 0.1 &#8211; in this case all the labels will be the same. So let&#8217;s modify our callback function to add extra decimals until the labels become distinct:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> myCallbackFunction<span style="color: #080;">&#40;</span>hProp,eventData<span style="color: #080;">&#41;</span>    <span style="color: #228B22;">%#ok - hProp is unused</span>
   hAxes = eventData.<span style="">AffectedObject</span>;
   tickValues = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAxes,<span style="color:#A020F0;">'YTick'</span><span style="color: #080;">&#41;</span>;
&nbsp;
   <span style="color: #228B22;">%newLabels = arrayfun(@(value)(sprintf('%.1fV',value)), tickValues, 'UniformOutput',false);</span>
   digits = <span style="color: #33f;">0</span>;
   labelsOverlap = <span style="color: #0000FF;">true</span>;
   <span style="color: #0000FF;">while</span> labelsOverlap
      <span style="color: #228B22;">% Add another decimal digit to the format until the labels become distinct</span>
      digits = digits + <span style="color: #33f;">1</span>;
      <span style="color: #0000FF;">format</span> = <span style="color: #0000FF;">sprintf</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'%%.%dfV'</span>,digits<span style="color: #080;">&#41;</span>;
      newLabels = arrayfun<span style="color: #080;">&#40;</span>@<span style="color: #080;">&#40;</span>value<span style="color: #080;">&#41;</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">sprintf</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">format</span>,value<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>, tickValues, <span style="color:#A020F0;">'UniformOutput'</span>,<span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
      labelsOverlap = <span style="color: #080;">&#40;</span><span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>newLabels<span style="color: #080;">&#41;</span> &gt; <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">unique</span><span style="color: #080;">&#40;</span>newLabels<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
      <span style="color: #228B22;">% prevent endless loop if the tick values themselves are non-unique</span>
      <span style="color: #0000FF;">if</span> labelsOverlap <span style="color: #F0F;">&amp;&amp;</span> <span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">diff</span><span style="color: #080;">&#40;</span>tickValues<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>&lt; <span style="color: #33f;">16</span>*<span style="color: #0000FF;">eps</span>
         <span style="color: #0000FF;">break</span>;
      <span style="color: #0000FF;">end</span>
   <span style="color: #0000FF;">end</span>
&nbsp;
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hAxes, <span style="color:#A020F0;">'YTickLabel'</span>, newLabels<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% myCallbackFunction</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 310px"><img
src="http://UndocumentedMatlab.com/images/PlotLabels_3a.png" alt="non-distinct labels" title="non-distinct labels" width="134" height="143" /> <img
src="http://UndocumentedMatlab.com/images/PlotLabels_3b.png" alt="distinct labels" title="distinct labels" width="134" height="143" /><p
class="wp-caption-text">Non-distinct labels &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; distinct labels</p></div></center></pre><h3 id="ticklabelformat"><i>ticklabelformat</i></h3><p>Based on a file that I received from an anonymous reader a few years ago, I have prepared a utility called <i><b>ticklabelformat</b></i> that automates much of the set-up above. Feel free to <a
target="_blank" href="http://www.mathworks.com/matlabcentral/fileexchange/36254-ticklabelformat">download</a> this utility and modify it for your needs - it's quite simple to read and follow. The usage syntax is as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">ticklabelformat<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'y'</span>,<span style="color:#A020F0;">'%.6g V'</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;">% sets y axis on current axes to display 6 significant digits</span>
ticklabelformat<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'xy'</span>,<span style="color:#A020F0;">'%.2f'</span><span style="color: #080;">&#41;</span>   <span style="color: #228B22;">% sets x &amp; y axes on current axes to display 2 decimal digits</span>
ticklabelformat<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'z'</span>,@myCbFcn<span style="color: #080;">&#41;</span>  <span style="color: #228B22;">% sets a function to update the Z tick labels on current axes</span>
ticklabelformat<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'z'</span>,<span style="color: #080;">&#123;</span>@myCbFcn,extraData<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;">% sets an update function as above, with extra data</span></pre></div></div><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/axes-looseinset-property/' rel='bookmark' title='Axes LooseInset property'>Axes LooseInset property</a> <small>Matlab plot axes have an undocumented LooseInset property that sets empty margins around the axes, and can be set to provide a tighter fit of the axes to their surroundings....</small></li><li><a
href='http://undocumentedmatlab.com/blog/determining-axes-zoom-state/' rel='bookmark' title='Determining axes zoom state'>Determining axes zoom state</a> <small>The information of whether or not an axes is zoomed or panned can easily be inferred from an internal undocumented object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/fig-files-format/' rel='bookmark' title='FIG files format'>FIG files format</a> <small>FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/customizing-matlab-labels/' rel='bookmark' title='Customizing Matlab labels'>Customizing Matlab labels</a> <small>Matlab's text uicontrol is not very customizable, and does not support HTML or Tex formatting. This article shows how to display HTML labels in Matlab and some undocumented customizations...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/setting-axes-tick-labels-format/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>getundoc &#8211; get undocumented object properties</title><link>http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/</link> <comments>http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/#comments</comments> <pubDate>Wed, 21 Sep 2011 19:00:16 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[HG2]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema.prop]]></category> <category><![CDATA[Undocumented property]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2437</guid> <description><![CDATA[getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/undocumented-cursorbar-object/' rel='bookmark' title='Undocumented cursorbar object'>Undocumented cursorbar object</a> <small>Matlab's internal undocumented graphics.cursorbar object can be used to present dynamic data-tip cross-hairs...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/' rel='bookmark' title='Displaying hidden handle properties'>Displaying hidden handle properties</a> <small>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Last week, I <a
target="_blank" href="http://undocumentedmatlab.com/blog/controlling-plot-data-tips/#Properties">presented</a> the list of undocumented properties available in Matlab&#8217;s cursor mode and data-tip objects. Over the past two years, I had posted <a
target="_blank" href="http://undocumentedmatlab.com/blog/category/hidden-property/">quite a few other articles</a> on this website that used such undocumented properties. So today I will show exactly how such properties can be discovered.</p><p>Hidden properties are object properties that for some reason or other MathWorks has decided not to expose to the general public. They can still be used by Matlab users, just like any other regular property. But if you use the built-in <i><b>get</b></i> and <i><b>set</b></i> functions to list the object&#8217;s properties, you will not find the hidden properties listed. You need to know the hidden properties&#8217; exact name in order to use them. Which is where today&#8217;s post can help, by showing you how to list these hidden properties. I <a
target="_blank" href="http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/">wrote about this</a> a couple of years ago, and today&#8217;s article will expand on that original post.</p><p>Hidden properties are by their very nature undocumented and not officially supported. For this reason, you should take extra care when relying on them in your code. They could change functionality or even be removed without prior notice in any future Matlab release. Still, some of these properties enable very important functionality, as I have often shown on this website.</p><h3 id="HideUndocumented">HideUndocumented</h3><p>There are two distinct manners by which undocumented properties can be seen in Matlab. The simplest was <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/1183#2277">reported</a> by Hans Olsson all the way back in 1997, in one of the very earliest posts on the CSSM newsgroup (there is no earlier public report, as far as I could tell). Since then, this method was mentioned in about a dozen <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/search_results?dur=all&#038;page=1&#038;query=hideundocumented&#038;search=+Go+&#038;search_string=hideundocumented&#038;search_submit=cssm">other CSSM posts</a>.</p><p>By setting the Matlab root (handle 0)&#8217;s <b>HideUndocumented</b> property to &#8216;off&#8217; (default=&#8217;on&#8217;), subsequent calls to the built-in <i><b>get</b></i> and <i><b>set</b></i> functions list the hidden properties in addition to the regular ones. Note that <b>HideUndocumented</b> is itself a hidden property, which is why Hans&#8217; post is so important &#8211; he presented us with the loose end that then enabled us to untangle the hidden properties in any other HG object.</p><p>Here is a simple example, showing <b>HideUndocumented</b>&#8216;s effect on the root (handle 0) object handle itself (hidden properties are highlighted):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Display only regular properties</span>
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>
	CallbackObject = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
	CommandWindowSize = <span style="color: #080;">&#91;</span><span style="color: #33f;">86</span> <span style="color: #33f;">51</span><span style="color: #080;">&#93;</span>
	CurrentFigure = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
	<span style="color: #0000FF;">Diary</span> = off
	DiaryFile = <span style="color: #0000FF;">diary</span>
	<span style="color: #0000FF;">Echo</span> = off
	FixedWidthFontName = Courier New
	<span style="color: #0000FF;">Format</span> = longG
	FormatSpacing = compact
	Language = he_il
	MonitorPositions = <span style="color: #080;">&#91;</span> <span style="color: #080;">&#40;</span><span style="color: #33f;">2</span> by <span style="color: #33f;">4</span><span style="color: #080;">&#41;</span> <span style="color: #0000FF;">double</span> array<span style="color: #080;">&#93;</span>
	<span style="color: #0000FF;">More</span> = off
	PointerLocation = <span style="color: #080;">&#91;</span><span style="color: #33f;">1084</span> <span style="color: #33f;">590</span><span style="color: #080;">&#93;</span>
	RecursionLimit = <span style="color: #080;">&#91;</span><span style="color: #33f;">500</span><span style="color: #080;">&#93;</span>
	ScreenDepth = <span style="color: #080;">&#91;</span><span style="color: #33f;">32</span><span style="color: #080;">&#93;</span>
	ScreenPixelsPerInch = <span style="color: #080;">&#91;</span><span style="color: #33f;">96</span><span style="color: #080;">&#93;</span>
	ScreenSize = <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">1</span> <span style="color: #33f;">1440</span> <span style="color: #33f;">900</span><span style="color: #080;">&#93;</span>
	ShowHiddenHandles = off
	Units = pixels
&nbsp;
	BeingDeleted = off
	ButtonDownFcn = 
	Children = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
	Clipping = on
	CreateFcn = 
	DeleteFcn = 
	BusyAction = queue
	HandleVisibility = on
	HitTest = on
	Interruptible = on
	Parent = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
	Selected = off
	SelectionHighlight = on
	Tag = 
	<span style="color: #0000FF;">Type</span> = root
	<span style="color: #0000FF;">UIContextMenu</span> = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
	UserData = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
	Visible = on
&nbsp;
<span style="color: #228B22;">% Display ALL properties (including hidden ones, which are highlighted below)</span>
&gt;&gt; <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'HideUndocumented'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>
<span style="display:block;background-color: #ffc;">	BlackAndWhite = off</span>	CallbackObject = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
	CommandWindowSize = <span style="color: #080;">&#91;</span><span style="color: #33f;">86</span> <span style="color: #33f;">51</span><span style="color: #080;">&#93;</span>
	CurrentFigure = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
	<span style="color: #0000FF;">Diary</span> = off
	DiaryFile = <span style="color: #0000FF;">diary</span>
	<span style="color: #0000FF;">Echo</span> = off
<span style="display:block;background-color: #ffc;">	ErrorMessage = <span style="color: #080;">&#91;</span> <span style="color: #080;">&#40;</span><span style="color: #33f;">1</span> by <span style="color: #33f;">79</span><span style="color: #080;">&#41;</span> <span style="color: #0000FF;">char</span> array<span style="color: #080;">&#93;</span></span>	FixedWidthFontName = Courier New
	<span style="color: #0000FF;">Format</span> = longG
	FormatSpacing = compact
<span style="display:block;background-color: #ffc;">	HideUndocumented = off</span>	Language = he_il
	MonitorPositions = <span style="color: #080;">&#91;</span> <span style="color: #080;">&#40;</span><span style="color: #33f;">2</span> by <span style="color: #33f;">4</span><span style="color: #080;">&#41;</span> <span style="color: #0000FF;">double</span> array<span style="color: #080;">&#93;</span>
	<span style="color: #0000FF;">More</span> = off
	PointerLocation = <span style="color: #080;">&#91;</span><span style="color: #33f;">1022</span> <span style="color: #33f;">82</span><span style="color: #080;">&#93;</span>
<span style="display:block;background-color: #ffc;">	PointerWindow = <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span><span style="color: #080;">&#93;</span></span>	RecursionLimit = <span style="color: #080;">&#91;</span><span style="color: #33f;">500</span><span style="color: #080;">&#93;</span>
	ScreenDepth = <span style="color: #080;">&#91;</span><span style="color: #33f;">32</span><span style="color: #080;">&#93;</span>
	ScreenPixelsPerInch = <span style="color: #080;">&#91;</span><span style="color: #33f;">96</span><span style="color: #080;">&#93;</span>
	ScreenSize = <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">1</span> <span style="color: #33f;">1440</span> <span style="color: #33f;">900</span><span style="color: #080;">&#93;</span>
	ShowHiddenHandles = off
	Units = pixels
<span style="display:block;background-color: #ffc;">	AutomaticFileUpdates = on</span>&nbsp;
	BeingDeleted = off
<span style="display:block;background-color: #ffc;">	PixelBounds = <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span> <span style="color: #33f;">0</span> <span style="color: #33f;">0</span> <span style="color: #33f;">0</span><span style="color: #080;">&#93;</span></span>	ButtonDownFcn = 
	Children = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
	Clipping = on
	CreateFcn = 
	DeleteFcn = 
	BusyAction = queue
	HandleVisibility = on
<span style="display:block;background-color: #ffc;">	HelpTopicKey = </span>	HitTest = on
	Interruptible = on
	Parent = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
	Selected = off
	SelectionHighlight = on
<span style="display:block;background-color: #ffc;">	Serializable = on</span>	Tag = 
	<span style="color: #0000FF;">Type</span> = root
	<span style="color: #0000FF;">UIContextMenu</span> = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
	UserData = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
<span style="display:block;background-color: #ffc;">	ApplicationData = <span style="color: #080;">&#91;</span> <span style="color: #080;">&#40;</span><span style="color: #33f;">1</span> by <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span> <span style="color: #0000FF;">struct</span> array<span style="color: #080;">&#93;</span></span><span style="display:block;background-color: #ffc;">	Behavior = <span style="color: #080;">&#91;</span> <span style="color: #080;">&#40;</span><span style="color: #33f;">1</span> by <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span> <span style="color: #0000FF;">struct</span> array<span style="color: #080;">&#93;</span></span>	Visible = on
<span style="display:block;background-color: #ffc;">	XLimInclude = on</span><span style="display:block;background-color: #ffc;">	YLimInclude = on</span><span style="display:block;background-color: #ffc;">	ZLimInclude = on</span><span style="display:block;background-color: #ffc;">	CLimInclude = on</span><span style="display:block;background-color: #ffc;">	ALimInclude = on</span><span style="display:block;background-color: #ffc;">	IncludeRenderer = on</span></pre></div></div><h3 id="schema">Property definitions</h3><p>An entirely different mechanism uses the <i><b>schema.prop</b></i> definitions that were <a
target="_blank" href="http://undocumentedmatlab.com/blog/udd-properties/">presented here</a> by Donn Scull at the beginning of 2011. The idea is to get the object&#8217;s <i><b>classhandle</b></i> reference, from it to get the list of properties definitions, and for each property look at its <b>Visible</b> meta-property: hidden properties will simply have <b>Visible</b>=&#8217;off&#8217;, whereas regular properties will have &#8216;on&#8217;.</p><p>It turns out that there is not always a full correspondence between these two mechanism. I can&#8217;t remember specific examples, and perhaps these were fixed in the latest Matlab releases. It doesn&#8217;t matter, because merging the list of hidden properties reported by these two methods is always safe to do. Which is exactly what my <i><b>getundoc</b></i> utility does:</p><h3 id="getundoc">getundoc utility</h3><p>The <i><b>getundoc</b></i> utility is based on another utility by the same name, posted by <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/authors/31831">Duane Hanselman</a> to the Matlab File Exchange in 2006 (Duane has elected to remove all his submissions from FEX a year or two ago, but that&#8217;s an entirely separate [and extremely heated] topic for a different discussion). Duane&#8217;s original <i><b>getundoc</b></i> utility relied only on the first (<b>HideUndocumented</b>) mechanism.</p><p>I have since expanded this utility to include support for the second mechanism, as well as support for the upcoming HG2 (see below). The updated <i><b>getundoc</b></i> is now <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/32934-getundoc-get-undocumented-object-properties">available for download</a> on the File Exchange. Since it&#8217;s a very short utility, I will digress from my norm and simply present its code, in its present form, here:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> c = getundoc<span style="color: #080;">&#40;</span>arg<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%GETUNDOC Get Undocumented Object Properties.</span>
<span style="color: #228B22;">% GETUNDOC('OBJECT') or GETUNDOC(H) returns a structure of</span>
<span style="color: #228B22;">% undocumented properties (names &amp; values) for the object having handle</span>
<span style="color: #228B22;">% H or indentified by the string 'OBJECT'.</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">% For example, GETUNDOC('axes') or GETUNDOC(gca) returns undocumented</span>
<span style="color: #228B22;">% property names and values for the axes object.</span>
&nbsp;
<span style="color: #228B22;">% Extension of Duane Hanselman's original utility (which is no longer</span>
<span style="color: #228B22;">% available on the File Exchange):</span>
<span style="color: #228B22;">% D.C. Hanselman, University of Maine, Orono, ME 04469</span>
<span style="color: #228B22;">% MasteringMatlab@yahoo.com</span>
<span style="color: #228B22;">% Mastering MATLAB 7</span>
<span style="color: #228B22;">% 2006-01-06</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #0000FF;">nargin</span>~=<span style="color: #33f;">1</span>
   <span style="color: #0000FF;">error</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'One Input Required.'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">if</span> <span style="color: #0000FF;">ischar</span><span style="color: #080;">&#40;</span>arg<span style="color: #080;">&#41;</span> <span style="color: #228B22;">% GETUNDOC('OBJECT')</span>
   <span style="color: #0000FF;">switch</span> <span style="color: #0000FF;">lower</span><span style="color: #080;">&#40;</span>arg<span style="color: #080;">&#41;</span>
   <span style="color: #0000FF;">case</span> <span style="color:#A020F0;">'root'</span>                                                       <span style="color: #228B22;">% root</span>
      h=<span style="color: #33f;">0</span>;
      hf=<span style="color: #33f;">0</span>;
   <span style="color: #0000FF;">case</span> <span style="color:#A020F0;">'figure'</span>                                                   <span style="color: #228B22;">% figure</span>
      h=<span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Visible'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
      hf=h;
   <span style="color: #0000FF;">otherwise</span>                          <span style="color: #228B22;">% some other string name of an object</span>
      hf=<span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Visible'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
      object=str2func<span style="color: #080;">&#40;</span>arg<span style="color: #080;">&#41;</span>;
      <span style="color: #0000FF;">try</span>
         h=object<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Parent'</span>,hf,<span style="color:#A020F0;">'Visible'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
      <span style="color: #0000FF;">catch</span>
         <span style="color: #0000FF;">error</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Unknown Object Type String Provided.'</span><span style="color: #080;">&#41;</span>         
      <span style="color: #0000FF;">end</span>
   <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">elseif</span> <span style="color: #0000FF;">ishandle</span><span style="color: #080;">&#40;</span>arg<span style="color: #080;">&#41;</span> <span style="color: #228B22;">% GETUNDOC(H)</span>
   h=arg;
   hf=<span style="color: #33f;">0</span>;
<span style="color: #0000FF;">else</span>
   <span style="color: #0000FF;">error</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Unknown Object Handle Provided.'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">end</span>
&nbsp;
wstate=<span style="color: #0000FF;">warning</span>;
<span style="color: #0000FF;">warning</span> off                                      <span style="color: #228B22;">% supress warnings about obsolete properties</span>
<span style="color: #0000FF;">try</span> <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'HideUndocumented'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">catch</span>; <span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% Fails in HG2</span>
undocfnames=<span style="color: #0000FF;">fieldnames</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>h<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;                  <span style="color: #228B22;">% get props including undocumented</span>
<span style="color: #0000FF;">try</span> <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'HideUndocumented'</span>,<span style="color:#A020F0;">'on'</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">catch</span>; <span style="color: #0000FF;">end</span>   <span style="color: #228B22;">% Fails in HG2</span>
docfnames=<span style="color: #0000FF;">fieldnames</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>h<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;                    <span style="color: #228B22;">% get props excluding undocumented</span>
&nbsp;
<span style="color: #228B22;">% Yair 18/3/2010 - add a few more undocs:</span>
<span style="color: #0000FF;">try</span>
    <span style="color: #228B22;">% This works in HG1</span>
    props = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>classhandle<span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>h<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'properties'</span><span style="color: #080;">&#41;</span>;
    undocfnames = <span style="color: #080;">&#91;</span>undocfnames; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>props<span style="color: #080;">&#40;</span><span style="color: #0000FF;">strcmp</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>props,<span style="color:#A020F0;">'Visible'</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'Name'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span>;
<span style="color: #0000FF;">catch</span>
    <span style="color: #228B22;">% Yair 18/9/2011: In HG2, the above fails, so use the following workaround:</span>
    <span style="color: #0000FF;">try</span>
        prop = <span style="color: #0000FF;">findprop</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>h<span style="color: #080;">&#41;</span>,undocfnames<span style="color: #080;">&#123;</span><span style="color: #33f;">1</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
        props = prop.<span style="">DefiningClass</span>.<span style="">PropertyList</span>;
        undocfnames = <span style="color: #080;">&#91;</span>undocfnames; <span style="color: #080;">&#123;</span>props.<span style="">Name</span><span style="color: #080;">&#125;</span>'<span style="color: #080;">&#93;</span>;   <span style="color: #228B22;">% {props([props.Hidden]).Name}</span>
    <span style="color: #0000FF;">catch</span>
        <span style="color: #228B22;">% ignore...</span>
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span>
&nbsp;
c = <span style="color: #0000FF;">setdiff</span><span style="color: #080;">&#40;</span>undocfnames,docfnames<span style="color: #080;">&#41;</span>;      <span style="color: #228B22;">% extract undocumented</span>
&nbsp;
<span style="color: #228B22;">% Get the values in struct format, if relevant</span>
<span style="color: #0000FF;">if</span> ~<span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>c<span style="color: #080;">&#41;</span>
  s = <span style="color: #0000FF;">struct</span>;
  <span style="color: #0000FF;">for</span> fieldIdx = <span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>c<span style="color: #080;">&#41;</span>
      <span style="color: #0000FF;">try</span>
          fieldName = c<span style="color: #080;">&#123;</span>fieldIdx<span style="color: #080;">&#125;</span>;
          s.<span style="color: #080;">&#40;</span>fieldName<span style="color: #080;">&#41;</span> = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>h,fieldName<span style="color: #080;">&#41;</span>;
      <span style="color: #0000FF;">catch</span>
          s.<span style="color: #080;">&#40;</span>fieldName<span style="color: #080;">&#41;</span> = <span style="color:#A020F0;">'???'</span>;
      <span style="color: #0000FF;">end</span>
  <span style="color: #0000FF;">end</span>
  c = s;
<span style="color: #0000FF;">end</span>
<span style="color: #228B22;">% Yair end</span>
&nbsp;
<span style="color: #0000FF;">if</span> hf~=<span style="color: #33f;">0</span>                     <span style="color: #228B22;">% delete hidden figure holding selected object</span>
   <span style="color: #0000FF;">delete</span><span style="color: #080;">&#40;</span>hf<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">warning</span><span style="color: #080;">&#40;</span>wstate<span style="color: #080;">&#41;</span></pre></div></div><p>Usage of this utility is extremely simple:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; getundoc<span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> = 
             ALimInclude<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
         ApplicationData<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
    AutomaticFileUpdates<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                Behavior<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
           BlackAndWhite<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
             CLimInclude<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
            ErrorMessage<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x79 <span style="color: #0000FF;">char</span><span style="color: #080;">&#93;</span>
            HelpTopicKey<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
        HideUndocumented<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
         IncludeRenderer<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
             PixelBounds<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span> <span style="color: #33f;">0</span> <span style="color: #33f;">0</span> <span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>
           PointerWindow<span style="color: #F0F;">:</span> <span style="color: #33f;">0</span>
            Serializable<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
             XLimInclude<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
             YLimInclude<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
             ZLimInclude<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
&nbsp;
&gt;&gt; getundoc<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> = 
               ALimInclude<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
    ActivePositionProperty<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'position'</span>
           ApplicationData<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
              BackingStore<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                  Behavior<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
               CLimInclude<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                CurrentKey<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
           CurrentModifier<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>1x0 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
                 Dithermap<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>64x3 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
             DithermapMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'manual'</span>
              DoubleBuffer<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
            ExportTemplate<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
               FixedColors<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>3x3 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
                   HelpFcn<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
              HelpTopicKey<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
              HelpTopicMap<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
           IncludeRenderer<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                 JavaFrame<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 com.<span style="">mathworks</span>.<span style="">hg</span>.<span style="">peer</span>.<span style="">HG1FigurePeer</span><span style="color: #080;">&#93;</span>
               MinColormap<span style="color: #F0F;">:</span> <span style="color: #33f;">64</span>
             OuterPosition<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">436</span> <span style="color: #33f;">374</span> <span style="color: #33f;">568</span> <span style="color: #33f;">502</span><span style="color: #080;">&#93;</span>
               PixelBounds<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span> <span style="color: #33f;">0</span> <span style="color: #33f;">560</span> <span style="color: #33f;">420</span><span style="color: #080;">&#93;</span>
             PrintTemplate<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
              Serializable<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                    UseHG2<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
                WaitStatus<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
               XLimInclude<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
               YLimInclude<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
               ZLimInclude<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span></pre></div></div><h3 id="HG2">Fixes for HG2</h3><p>Unfortunately, in the new <a
target="_blank" href="http://undocumentedmatlab.com/blog/matlab-hg2/">HG2</a> (which is still not in production, but we must be prepared, mustn&#8217;t we?), the original mechanism above (<b>HideUndocumented</b>) fails completely (there is no such property in the new <code>matlab.ui.root</code> object), whereas the second mechanism (UDD property defs) needs to be modified: Apparently, <i><b>classhandle</b></i> fails for HG2 object handles. Instead, we use the workaround of using <i><b>findprop</b></i> to get the property definition for any regular property, then get its parent (the requested class definition), and then down again to list all available properties. Note that in HG2, the relevant meta-property is <b>Hidden</b> which holds logical (<b><i>true/false</i></b>) values, as opposed to <b>Visible</b> and &#8216;off&#8217;/'on&#8217; values for HG1 above.</p><p>All of these fixes are now incorporated in the <i><b>getundoc</b></i> code that is listed above.</p><p>When comparing the list of hidden properties in the existing HG1 and the new HG2, we see many interesting differences. And yes: the figure&#8217;s <a
target="_blank" href="http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/#JavaFrame"><b>JavaFrame</b></a> property was indeed removed in HG2. Bummer! (don&#8217;t worry &#8211; there are several workarounds up my sleeve&#8230;)</p><p>Do you have any favorite hidden property that you use in your code? If so, please tell us about it in a comment <a
href="http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/#respond">below</a>.</p><p>p.s. &#8211; For all the numerous good people telling me about <a
target="_blank" href="http://undocumentedmatlab.com/blog/cprintf-display-formatted-color-text-in-command-window/"><i><b>cprintf</b></i></a> &#8211; Yes: I am aware that the latest R2011b release has broken <i><b>cprintf</b></i>&#8216;s functionality. I plan to release a workaround sometime soon, when I have some spare time. I&#8217;ll keep everybody posted of course. Please be patient. (if you can&#8217;t wait, you can always <a
target="_blank" href="http://undocumentedmatlab.com/consulting/">hire me</a> to fix it sooner; otherwise I need to give priority to my paying clients&#8230;)</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/undocumented-cursorbar-object/' rel='bookmark' title='Undocumented cursorbar object'>Undocumented cursorbar object</a> <small>Matlab's internal undocumented graphics.cursorbar object can be used to present dynamic data-tip cross-hairs...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/' rel='bookmark' title='Displaying hidden handle properties'>Displaying hidden handle properties</a> <small>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>UDD Events and Listeners</title><link>http://undocumentedmatlab.com/blog/udd-events-and-listeners/</link> <comments>http://undocumentedmatlab.com/blog/udd-events-and-listeners/#comments</comments> <pubDate>Wed, 16 Mar 2011 18:43:16 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Guest bloggers]]></category> <category><![CDATA[Listeners]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Donn Shull]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Listener]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema]]></category> <category><![CDATA[schema.prop]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2200</guid> <description><![CDATA[UDD event listeners can be used to listen to property value changes and other important events of Matlab objects<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events/' rel='bookmark' title='Matlab callbacks for Java events'>Matlab callbacks for Java events</a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li><li><a
href='http://undocumentedmatlab.com/blog/introduction-to-udd/' rel='bookmark' title='Introduction to UDD'>Introduction to UDD</a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li><li><a
href='http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/' rel='bookmark' title='Creating a simple UDD class'>Creating a simple UDD class</a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p><i>Donn Shull continues his exploration of the undocumented UDD mechanism, today discussing the important and extremely useful topic of UDD events</i></p><h3 id="model">The UDD event model</h3><p>The UDD event model is very similar to the MCOS event model. There is an excellent <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/matlab_oop/bqvggvt.html">discussion</a> of the MCOS event model in Matlab&#8217;s official documentation. Most of the MCOS information also applies to UDD if you make the following substitutions:</p><table><tbody><tr><th
bgcolor="#D0D0D0">MCOS Event Model</th><th
bgcolor="#D0D0D0">UDD Event Model</th></tr><tr><td
bgcolor="#E7E7E7">notify</td><td
bgcolor="#E7E7E7">send</td></tr><tr><td
bgcolor="#E7E7E7">event.EventData</td><td
bgcolor="#E7E7E7">handle.EventData</td></tr><tr><td
bgcolor="#E7E7E7">events block</td><td
bgcolor="#E7E7E7">schema.event</td></tr><tr><td
bgcolor="#E7E7E7">event.listener</td><td
bgcolor="#E7E7E7">handle.listener</td></tr><tr><td
bgcolor="#E7E7E7">PreGet, PreSet</td><td
bgcolor="#E7E7E7">PropertyPreGet, PropertPreSet</td></tr><tr><td
bgcolor="#E7E7E7">PostGet, PostSet</td><td
bgcolor="#E7E7E7">PropertyPostGet, PropertyPostSet</td></tr></tbody></table><h3 id="handler">Event handler functions</h3><p>To begin the UDD event model discussion we will start at the end, with the event handler. The event handler function requires at least two input arguments: the source object which triggered the event, and an object of type <code>handle.EventData</code> or a subclass of <code>handle.EventData</code>.</p><p>To demonstrate how this works, let&#8217;s write a simple event handler function. This event handler will display the class of the source event and the class of the event data:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> displayEventInfo<span style="color: #080;">&#40;</span>source, eventData<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%DISPLAYEVENTINFO display the classes of source, data objects</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   DISPLAYEVENTINFO(SOURCE, EVENTDATA) returns the classes</span>
<span style="color: #228B22;">%   of the source object and the event data object</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   INPUTS:</span>
<span style="color: #228B22;">%       SOURCE    : the event source</span>
<span style="color: #228B22;">%       EVENTDATA : the event data</span>
  <span style="color: #0000FF;">if</span> ~<span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>source<span style="color: #080;">&#41;</span>
    <span style="color: #0000FF;">fprintf</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>, <span style="color:#A020F0;">'The source object class is: %s'</span>,<span style="color: #0000FF;">class</span><span style="color: #080;">&#40;</span>source<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">end</span>
  <span style="color: #0000FF;">if</span> ~<span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>eventData<span style="color: #080;">&#41;</span>
    <span style="color: #0000FF;">fprintf</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>, <span style="color:#A020F0;">'The event data class is: %s'</span>,<span style="color: #0000FF;">class</span><span style="color: #080;">&#40;</span>eventData<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div><h3 id="listener">Creating a listener</h3><p>In the section on <a
target="_blank" href="http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/">Creating a Simple UDD Class</a> we used <code>schema.event</code> in our <code>simple.object</code> class definition file to create a <code>simpleEvent</code> event. We now create an instance of <code>simple.object</code>, then use <b><i>handle.listener</i></b> to wait (&#8220;listen&#8221;) for the <code>simpleEvent</code> event to occur and call the <i>displayEventInfo</i> event handler function:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">a = simple.<span style="">object</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'a'</span>, <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
hListener = <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>a,<span style="color:#A020F0;">'simpleEvent'</span>,@displayEventInfo<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">setappdata</span><span style="color: #080;">&#40;</span>a, <span style="color:#A020F0;">'listeners'</span>, hListener<span style="color: #080;">&#41;</span>;</pre></div></div><p><b><u>Important:</u></b> The <code>hListener</code> handle must remain stored somewhere in Matlab memory, or the listener will not be used. For this reason, it is good practice to attach the listener handle to the listened object, using the <i><b>setappdata</b></i> function, as was done above. The listener will then be alive for exactly as long as its target object is alive.</p><h3 id="EventData">Creating an EventData object</h3><p>Next, create the <code>handle.EventData</code> object. The <code>handle.EventData</code> object constructor requires two arguments: an instance of the events source object, and the name of the event:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">evtData = handle.<span style="">EventData</span><span style="color: #080;">&#40;</span>a, <span style="color:#A020F0;">'simpleEvent'</span><span style="color: #080;">&#41;</span></pre></div></div><h3 id="event">Generating an event</h3><p>The last step is actually triggering an event. This is done by issuing the <i><b>send</b></i> command for the specified object, event name and event data:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; a.<span style="">send</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'simpleEvent'</span>, evtData<span style="color: #080;">&#41;</span>
The source object <span style="color: #0000FF;">class</span> <span style="color: #0000FF;">is</span><span style="color: #F0F;">:</span> simple.<span style="">object</span>
The event data <span style="color: #0000FF;">class</span> <span style="color: #0000FF;">is</span><span style="color: #F0F;">:</span> handle.<span style="">EventData</span></pre></div></div><p>If there is other information that you wish to pass to the callback function you can create a subclass of the <code>handle.EventData</code>. Add properties to hold your additional information and use your subclass as the second argument of the <i><b>send</b></i> method.</p><h3 id="builtin">Builtin UDD events</h3><p>The builtin <code>handle</code> package has six event data classes which are subclasses of the base <code>handle.EventData</code> class. Each of these classes is paired with specific UDD events that Matlab generates. Actions that trigger these events include creating/destroying an object, adding/removing objects from a hierarchy, and getting/setting property values. The following table lists the event names and <code>handle.*EventData</code> data types returned for these events:</p><table><tbody><tr><th
bgcolor="#D0D0D0">event data type</th><th
bgcolor="#D0D0D0">event trigger</th></tr><tr><td
bgcolor="#E7E7E7">handle.ClassEventData</td><td
bgcolor="#E7E7E7">ClassInstanceCreated</td></tr><tr><td
bgcolor="#E7E7E7">handle.EventData</td><td
bgcolor="#E7E7E7">ObjectBeingDestroyed</td></tr><tr><td
bgcolor="#E7E7E7">handle.ChildEventData</td><td
bgcolor="#E7E7E7">ObjectChildAdded, ObjectChildRemoved</td></tr><tr><td
bgcolor="#E7E7E7">handle.ParentEventData</td><td
bgcolor="#E7E7E7">ObjectParentChanged</td></tr><tr><td
bgcolor="#E7E7E7">handle.PropertyEventData</td><td
bgcolor="#E7E7E7">PropertyPreGet, PropertyPostGet</td></tr><tr><td
bgcolor="#E7E7E7">handle.PropertySetEventData</td><td
bgcolor="#E7E7E7">PropertyPreSet, PropertyPostSet</td></tr></tbody></table><p>As an example of some of these events let&#8217;s look at a <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/303232">question</a> recently asked on the CSSM newsgroup. The basic idea is that we want to monitor an axis, automatically make any added lines to be green in color, and prevent patches from being added.</p><p>The solution is to monitor the <code>ObjectChildAdded</code> event for an axis. We will write an event handler which checks the <code>handle.ChildEventData</code> to see what type of child was added. In the case of lines we will set their color to green; patch objects will be deleted from the axis. Here is our event handler function:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> modifyAxesChildren<span style="color: #080;">&#40;</span>~, eventData<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%MODIFYAXESCHILDREN monitor and axis and modify added children</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   MODIFYAXESCHILDREN(SOURCE,EVENTDATA) is an event handler to</span>
<span style="color: #228B22;">%   change newly-added lines to green and remove added patches</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   INPUTS:</span>
<span style="color: #228B22;">%       EVENTDATA : handle.ChildEventData object</span>
   <span style="color: #0000FF;">switch</span> eventData.<span style="">Child</span>.<span style="">classhandle</span>.<span style="">Name</span>
      <span style="color: #0000FF;">case</span> <span style="color:#A020F0;">'line'</span>
         eventData.<span style="">Child</span>.<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Color'</span>, <span style="color:#A020F0;">'green'</span><span style="color: #080;">&#41;</span>;
         <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Color changed to green.'</span><span style="color: #080;">&#41;</span>
      <span style="color: #0000FF;">case</span> <span style="color:#A020F0;">'patch'</span>
         eventData.<span style="">Child</span>.<span style="color: #0000FF;">delete</span>;
         <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Patch removed.'</span><span style="color: #080;">&#41;</span>
   <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div><p>Next create an axis, and a listener which is triggered when children are added:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% create a new axes and get its handle</span>
a = hg.<span style="color: #0000FF;">axes</span>;
&nbsp;
<span style="color: #228B22;">% create the listener</span>
listen = <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>a, <span style="color:#A020F0;">'ObjectChildAdded'</span>, @modifyAxesChildren<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% add a line</span>
&gt;&gt; hg.<span style="color: #0000FF;">line</span>;
Color changed to green.
&nbsp;
<span style="color: #228B22;">% try to add a patch</span>
&gt;&gt; hg.<span style="color: #0000FF;">patch</span>;
<span style="color: #0000FF;">Patch</span> removed.</pre></div></div><p>Removing a child with either the <i>delete</i> or the <i>disconnect</i> method generates an <code>ObjectChildRemoved</code> event. The <i>delete</i> method also generates the <code>ObjectBeingDestroyed</code> event. Changing a child&#8217;s parent with the <i>up</i> method generates an <code>ObjectParentChanged</code> event.</p><p>Reading an object&#8217;s properties with either dot notation or with the <i>get</i> method generates <code>PropertyPreGet</code> and <code>PropertyPostGet</code> events.</p><p>Changing the value of a property generates the <code>PropertyPreSet</code> and <code>PropertyPostSet</code> events. As we saw in the section on <a
target="_Blank" href="http://undocumentedmatlab.com/blog/udd-properties/">UDD properties</a>, when the <b>AbortSet</b> access flag is &#8216;on&#8217;, property set events are only generated when a <i><b>set</b></i> operation actually changes the value of the property (as opposed to leaving it unchanged).</p><p>Note that the <b><i>handle.listener</i></b> syntax is slightly different for property events:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hProp = <span style="color: #0000FF;">findprop</span><span style="color: #080;">&#40;</span>a, <span style="color:#A020F0;">'Value'</span><span style="color: #080;">&#41;</span>;
hListener = <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>a,hProp,<span style="color:#A020F0;">'PropertyPreGet'</span>,@displayEventInfo<span style="color: #080;">&#41;</span>;</pre></div></div><h3 id="Java">Java events</h3><p>The final specialized event data object in the handle package is <code>handle.JavaEventData</code>. In Matlab, Java classes are not UDD classes, but each Java instance can have a UDD <i>peer</i>. The peer is created using the <i><b>handle</b></i> function. The Java peers are created in either UDD&#8217;s <code>javahandle</code> package or the <code>javahandle_withcallbacks</code> package. As their names imply, the latter enables listening to Java-triggered events using a Matlab callback.</p><p>To illustrate how this works we will create a Java Swing <code>JFrame</code> and listen for <code>MouseClicked</code> events:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Create the Java Frame</span>
javaFrame = javax.<span style="">swing</span>.<span style="">JFrame</span>;
javaFrame.<span style="">setSize</span><span style="color: #080;">&#40;</span><span style="color: #33f;">200</span>, <span style="color: #33f;">200</span><span style="color: #080;">&#41;</span>;
javaFrame.<span style="">show</span>;
&nbsp;
<span style="color: #228B22;">% Create a UDD peer for the new JFrame (two alternatives)</span>
javaFramePeer = javaFrame.<span style="">handle</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'CallbackProperties'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% alternative #1</span>
javaFramePeer = handle<span style="color: #080;">&#40;</span>javaFrame, <span style="color:#A020F0;">'CallbackProperties'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% alternative #2</span>
&nbsp;
<span style="color: #228B22;">% Create the a listener for the Java MouseClicked event</span>
listen = <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>javaFramePeer, <span style="color:#A020F0;">'MouseClicked'</span>, @displayEventInfo<span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 210px"><img
alt="a simple Java Swing JFrame" src="http://UndocumentedMatlab.com/images/UDD_Java_Frame.png" title="a simple Java Swing JFrame" width="200" height="200" /><p
class="wp-caption-text">a simple Java Swing JFrame</p></div></center></p><p>When we click on the JFrame, our UDD peer triggers the callback:</p><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;">The source object <span style="color: #000000; font-weight: bold;">class</span> is<span style="color: #339933;">:</span> javahandle_withcallbacks.<span style="color: #006633;">javax</span>.<span style="color: #006633;">swing</span>.<span style="color: #003399;">JFrame</span>
The event data <span style="color: #000000; font-weight: bold;">class</span> is<span style="color: #339933;">:</span> handle.<span style="color: #006633;">JavaEventData</span></pre></div></div><p>Since we created our peer in the <code>javahandle_withcallbacks</code> package, it is not necessary to create a listener using <i><b>handle.listener</b></i>. If we place our callback function handle in the <b>MouseClickedCallback</b> property it will be executed whenever the <code>MouseClicked</code> event is triggered. Such <b>*Callback</b> properties are automatically generated by Matlab when it creates the UDD peer (<a
target="_blank" href="http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events/">details</a>).</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">clear</span> listen
javaFramePeer.<span style="">MouseClickedCallback</span> = @displayEventInfo</pre></div></div><p>This will work the same as before without the need to create and maintain a <b><i>handle.listener</i></b> object. If we had created our UDD peer in the <code>javahandle</code> package rather than <code>javahandle_withcallbacks</code>, we would not have the convenience of the <b>MouseClickedCallback</b> property, but we could still use the <b><i>handle.listener</i></b> mechanism to monitor events.</p><h3 id="custom">Creating callback properties for custom UDD classes</h3><p>It is easy to add callback properties to user created UDD objects. The technique involves embedding a <code>handle.listener</code> object in the UDD object. To illustrate this, we add a <b>SimpleEventCallback</b> property to our <code>simple.object</code>, then use a <b>SimpleEventListener</b> property to hold our embedded <b><i>handle.listener</i></b>. Add the following to <code>simple.object</code>&#8216;s schema.m definition file:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">   <span style="color: #228B22;">% Property to hold our callback handle</span>
   prop = schema.<span style="">prop</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'SimpleEventCallback'</span>, <span style="color:#A020F0;">'MATLAB callback'</span><span style="color: #080;">&#41;</span>;
   prop.<span style="">setFunction</span> = @setValue;
&nbsp;
   <span style="color: #228B22;">% hidden property to hold the listener for our callback</span>
   prop = schema.<span style="">prop</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'SimpleEventListener'</span>, <span style="color:#A020F0;">'handle'</span><span style="color: #080;">&#41;</span>;
   prop.<span style="">Visible</span> = <span style="color:#A020F0;">'off'</span>;
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #0000FF;">function</span> propVal = setValue<span style="color: #080;">&#40;</span>self, value<span style="color: #080;">&#41;</span>
   <span style="color: #228B22;">%SETVALUE function to transfer function handle from callback property to listener</span>
   self.<span style="">SimpleEventListener</span>.<span style="">Callback</span> = value;
   propVal = value;
<span style="color: #0000FF;">end</span></pre></div></div><p>Next we add the following to our simple.object constructor file:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% set the hidden listener property to a handle.listener</span>
simpleObject.<span style="">SimpleEventListener</span> = <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>simpleObject, <span style="color:#A020F0;">'simpleEvent'</span>, <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>Now if we set the <b>SimpleObjectCallback</b> property to a function handle, the handle is transferred to the embedded <b><i>handle.listener</i></b> Callback property. When a <code>simpleEvent</code> event is generated, our <code>SimpleEventCallback</code> function will be executed.</p><p>This series will conclude next week with a look at the special relationship between UDD and Java.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events/' rel='bookmark' title='Matlab callbacks for Java events'>Matlab callbacks for Java events</a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li><li><a
href='http://undocumentedmatlab.com/blog/introduction-to-udd/' rel='bookmark' title='Introduction to UDD'>Introduction to UDD</a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li><li><a
href='http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/' rel='bookmark' title='Creating a simple UDD class'>Creating a simple UDD class</a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/udd-events-and-listeners/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>UDD Properties</title><link>http://undocumentedmatlab.com/blog/udd-properties/</link> <comments>http://undocumentedmatlab.com/blog/udd-properties/#comments</comments> <pubDate>Wed, 09 Mar 2011 18:00:17 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Guest bloggers]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Donn Shull]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema]]></category> <category><![CDATA[schema.prop]]></category> <category><![CDATA[Undocumented property]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2156</guid> <description><![CDATA[UDD provides a very convenient way to add customizable properties to existing Matlab object handles<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/' rel='bookmark' title='getundoc &#8211; get undocumented object properties'>getundoc &#8211; get undocumented object properties</a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/' rel='bookmark' title='Displaying hidden handle properties'>Displaying hidden handle properties</a> <small>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles...</small></li><li><a
href='http://undocumentedmatlab.com/blog/borderless-button-used-for-plot-properties/' rel='bookmark' title='Borderless button used for plot properties'>Borderless button used for plot properties</a> <small>A borderless button can be used to add unobtrusive functionality to plot axes...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p><i>Donn Shull continues his series of articles on Matlab&#8217;s undocumented UDD mechanism. Today, Donn explains how to use and customize UDD properties.</i></p><h3 id="meta-data">Properties meta-data</h3><p>The UDD system is a class system. UDD packages, classes, events, and properties are all classes. In this section we will take a closer look at property classes.</p><p>As we have <a
target="_blank" href="http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/">already shown</a>, properties are added to a UDD class by adding <code>schema.prop</code> calls to the schema.m class definition file. What this really means is that each property of a UDD class is itself a class object (<code>schema.prop</code>) with its own properties and methods. The methods of <code>schema.prop</code> are <i>loadobj()</i> and <i>saveobj()</i>, which are used to serialize objects of this class (i.e., storing them in a file or sending them elsewhere).</p><p>It is <code>schema.prop</code>&#8216;s properties (so-called <i>meta-properties</i>) that interest us most:</p><table><tr><th
bgcolor="#D0D0D0">Property</th><th
bgcolor="#D0D0D0">Data Type</th><th
bgcolor="#D0D0D0">Description</th></tr><tr><td
bgcolor="#E7E7E7">AccessFlags</td><td
bgcolor="#E7E7E7">Matlab structure</td><td
bgcolor="#E7E7E7">Controls which objects can access (read/modify) the property</td></tr><tr><td
bgcolor="#E7E7E7">CaseSensitive</td><td
bgcolor="#E7E7E7">on/off</td><td
bgcolor="#E7E7E7">Determines if the exact case is required to access the property (i.e., can we use &#8216;casesensitive&#8217; instead of &#8216;CaseSensitive&#8217;)</td></tr><tr><td
bgcolor="#E7E7E7">DataType</td><td
bgcolor="#E7E7E7">string</td><td
bgcolor="#E7E7E7">The underlying object&#8217;s property data type, set by the constructor</td></tr><tr><td
bgcolor="#E7E7E7">Description</td><td
bgcolor="#E7E7E7">string</td><td
bgcolor="#E7E7E7">This can hold a description of the property (normally empty)</td></tr><tr><td
bgcolor="#E7E7E7">FactoryValue</td><td
bgcolor="#E7E7E7">As specified by DataType</td><td
bgcolor="#E7E7E7">This is used to provide an initial or default property value</td></tr><tr><td
bgcolor="#E7E7E7">GetFunction</td><td
bgcolor="#E7E7E7">Function handle</td><td
bgcolor="#E7E7E7">A function handle that is called whenever the property value is read</td></tr><tr><td
bgcolor="#E7E7E7">Name</td><td
bgcolor="#E7E7E7">string</td><td
bgcolor="#E7E7E7">The name of the property, also set by the constructor</td></tr><tr><td
bgcolor="#E7E7E7">SetFunction</td><td
bgcolor="#E7E7E7">Function handle</td><td
bgcolor="#E7E7E7">A function handle that is called whenever the properties value is changed</td></tr><tr><td
bgcolor="#E7E7E7">Visible</td><td
bgcolor="#E7E7E7">on/off</td><td
bgcolor="#E7E7E7">Determines if a property will be displayed by the <i><b>get</b></i> method for a UDD object</td></tr></table><p>We can manipulate the values of these meta-properties to control various aspects of our property:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Create instance of simple.object</span>
&gt;&gt; a = simple.<span style="">object</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'a'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Find the Value property and list its meta-properties</span>
<span style="color: #228B22;">% We can manipulate these meta-properties within limits</span>
&gt;&gt; a.<span style="color: #0000FF;">findprop</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Value'</span><span style="color: #080;">&#41;</span>.<span style="color: #0000FF;">get</span>
            Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'Value'</span>
     Description<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
        DataType<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'single'</span>
    FactoryValue<span style="color: #F0F;">:</span> <span style="color: #33f;">7.3891</span>
     AccessFlags<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
         Visible<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
     GetFunction<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
     SetFunction<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; prop.<span style="">Visible</span> = <span style="color:#A020F0;">'off'</span>;  <span style="color: #228B22;">% i.e. hidden property (see below)</span>
&gt;&gt; prop.<span style="">AccessFlags</span>.<span style="">PublicSet</span> = <span style="color:#A020F0;">'off'</span>;   <span style="color: #228B22;">% i.e. read-only</span>
&gt;&gt; prop.<span style="">AccessFlags</span>.<span style="">PublicGet</span> = <span style="color:#A020F0;">'on'</span>;
&nbsp;
<span style="color: #228B22;">% Find the DataType meta-property of the Value property</span>
<span style="color: #228B22;">% This meta-property and all other schema.prop base class properties are fixed</span>
&gt;&gt; a.<span style="color: #0000FF;">findprop</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Value'</span><span style="color: #080;">&#41;</span>.<span style="color: #0000FF;">findprop</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'DataType'</span><span style="color: #080;">&#41;</span>.<span style="color: #0000FF;">get</span>
            Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'DataType'</span>
     Description<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
        DataType<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'string'</span>
    FactoryValue<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
           <span style="color: #F0F;">...</span></pre></div></div><h3 id="new-prop">Adding properties to existing objects in run-time</h3><p><code>schema.prop</code> is a very useful tool &#8211; it can be used to add new properties to existing object handles, even after these objects have been created. For example, let&#8217;s add a new property (<b>MyFavoriteBlog</b>) to a standard figure handle:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; p=schema.<span style="">prop</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>, <span style="color:#A020F0;">'MyFavoriteBlog'</span>,<span style="color:#A020F0;">'string'</span><span style="color: #080;">&#41;</span>
p =
	schema.<span style="">prop</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'MyFavoriteBlog'</span>,<span style="color:#A020F0;">'UndocumentedMatlab.com'</span><span style="color: #080;">&#41;</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'MyFavoriteBlog'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
UndocumentedMatlab.<span style="">com</span></pre></div></div><p>Using this simple mechanism, we can add meaningful typed user data to any handle object. A similar functionality can be achieved via the <i><b>setappdata/getappdata</b></i> functions. However, the property-based approach above is much &#8220;cleaner&#8221; and more powerful, since we have built-in type checks, property-change event listeners and other useful goodies.</p><h3 id="DataType">Property data types</h3><p>In the article on <a
target="_blank" href="http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/">creating UDD objects</a> we saw that the <b>Name</b> and <b>DataType</b> meta-properties are set by the <code>schema.prop</code> constructor. <b>Name</b> must be a valid Matlab variable name (see <i><b>isvarname</b></i>).</p><p><b>DataType</b> is more interesting: There are two equivalent universal data types, <code>'mxArray'</code>, and <code>'MATLAB array'</code>. With either of these two data types a property can be set to a any Matlab type. If we use a more specific data type (e.g., &#8216;string&#8217;, &#8216;double&#8217; or &#8216;handle&#8217;), Matlab automatically ensures the type validity whenever the property value is modified. In our <code>simple.object</code> we use &#8216;double&#8217; and &#8216;string&#8217;. You can experiment with these and see that the <b>Value</b> property will only allow scalar numeric values and the <b>Name</b> property will only allow character values:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>obj, <span style="color:#A020F0;">'Value'</span>, <span style="color:#A020F0;">'abcd'</span><span style="color: #080;">&#41;</span>
??? Parameter must be scalar.
&nbsp;
&gt;&gt; obj.<span style="">Value</span>=<span style="color:#A020F0;">'abcd'</span>
??? Parameter must be scalar.
&nbsp;
&gt;&gt; obj.<span style="">Name</span>=<span style="color: #33f;">123</span>
??? Parameter must be a string.</pre></div></div><p>The following table lists the basic UDD data types:</p><table><tr><th
bgcolor="#D0D0D0">Category</th><th
bgcolor="#D0D0D0">Data Type</th></tr><tr><td
bgcolor="#E7E7E7">Universal</td><td
bgcolor="#E7E7E7">MATLAB array, mxArray</td></tr><tr><td
bgcolor="#E7E7E7">Numeric Scalars</td><td
bgcolor="#E7E7E7">bool, byte, short, int, long, float, double</td></tr><tr><td
bgcolor="#E7E7E7">Numeric Vectors</td><td
bgcolor="#E7E7E7">Nints, NReals</td></tr><tr><td
bgcolor="#E7E7E7">Specialized Numeric</td><td
bgcolor="#E7E7E7">color, point, real point, real point3, rect, real rect</td></tr><tr><td
bgcolor="#E7E7E7">Enumeration</td><td
bgcolor="#E7E7E7">on/off</td></tr><tr><td
bgcolor="#E7E7E7">Strings</td><td
bgcolor="#E7E7E7">char, string, NStrings, string vector</td></tr><tr><td
bgcolor="#E7E7E7">Handle</td><td
bgcolor="#E7E7E7">handle, handle vector, MATLAB callback, GetFunction, SetFunction</td></tr><tr><td
bgcolor="#E7E7E7">Java</td><td
bgcolor="#E7E7E7">Any java class recognized by Matlab</td></tr></table><h3 id="user-types">User-defined data types</h3><p>While this is an extensive list, there are some obvious types missing. For example there are no unsigned integer types. To handle this UDD provides two facilities for creating your own data types. One is the <code>schema.EnumType</code>. As you can see, Matlab has had a form of enumerations for a really long time not just the last few releases. The other facility is <code>schema.UserType</code>.</p><p>With these two classes you can create any specialized data type you need. One word of caution: once you have created a new UDD data type it exists for the duration of that Matlab session. There is no equivalent of the <i><b>clear classes</b></i> mechanism for removing a data type. In addition once a new data type has been defined it cannot be redefined until Matlab is restarted.</p><p>Let&#8217;s use a <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/280282">problem discussed in the CSSM forum</a> as example. The essence of the problem is the need to flag a graphic line object as either editable or not. The proposed proposed is to add a new <b>Editable</b> property to an existing line handle. We will use <code>schema.EnumType</code> to create a new type named <code>'yes/no'</code> so that the new property could accept only &#8216;yes&#8217; and &#8216;no&#8217; values:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> tline = taggedLine<span style="color: #080;">&#40;</span><span style="color: #0000FF;">varargin</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%TAGGEDLINE create a line with Editable property</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   TLINE = TAGGEDLINE(VARARGIN) create a new handle graphics line</span>
<span style="color: #228B22;">%   and add 'Ediatable' property to line. Default property value is 'yes'.</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   INPUTS:</span>
<span style="color: #228B22;">%       VARARGIN  : property value pairs to pass to line</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   OUTPUTS:</span>
<span style="color: #228B22;">%       TLINE     : hg line object with Editable property</span>
&nbsp;
    <span style="color: #228B22;">% If undefined define yes/no datatype&lt;/font&gt;</span>
    <span style="color: #0000FF;">if</span> <span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>findtype<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'yes/no'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
        schema.<span style="">EnumType</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'yes/no'</span>, <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'yes'</span>, <span style="color:#A020F0;">'no'</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
    tline = <span style="color: #0000FF;">line</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">varargin</span><span style="color: #080;">&#123;</span><span style="color: #F0F;">:</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
    schema.<span style="">prop</span><span style="color: #080;">&#40;</span>tline, <span style="color:#A020F0;">'Editable'</span>, <span style="color:#A020F0;">'yes/no'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>It is necessary to test for the existence of a type before defining it, since trying to redefine a type will generate an error.</p><p>We can use this new <i>taggedLine()</i> function to create new line objects with the additional <b>Editable</b> property. Instead of adding a new property to the line class we could have defined a new class as a subclass of line:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> schema<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%SCHEMA  hg package definition function</span>
    schema.<span style="">package</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'hg'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>We create our class definition as a subclass of the handle graphics line class:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> schema<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%SCHEMA  hg.taggedline class definition function</span>
    <span style="color: #228B22;">% package definition</span>
    superPackage = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'hg'</span><span style="color: #080;">&#41;</span>;
    pkg = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'hg'</span><span style="color: #080;">&#41;</span>;
&nbsp;
    <span style="color: #228B22;">% class definition</span>
    c = schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#40;</span>pkg, <span style="color:#A020F0;">'taggedline'</span>, findclass<span style="color: #080;">&#40;</span>superPackage, <span style="color:#A020F0;">'line'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
    <span style="color: #0000FF;">if</span> <span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>findtype<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'yes/no'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
        schema.<span style="">EnumType</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'yes/no'</span>, <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'yes'</span>, <span style="color:#A020F0;">'no'</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
&nbsp;
    <span style="color: #228B22;">% add properties to class</span>
    schema.<span style="">prop</span><span style="color: #080;">&#40;</span>c, <span style="color:#A020F0;">'Editable'</span>, <span style="color:#A020F0;">'yes/no'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>And our constructor is:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> self = taggedline
<span style="color: #228B22;">%OBJECT constructor for the simple.object class</span>
    self = hg.<span style="">taggedline</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>Here we have placed the <code>schema.EnumType</code> definition in the class definition function. It is usually better to place type definition code in the package definition function, which is executed prior to any of the package classes and available in all classes. But in this particular case we are extending the built-in <code>hg</code> package and because <code>hg</code> is already defined internally, our package definition code is never actually executed.</p><p>The <code>schema.UserType</code> has the following constructor syntax:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">schema.<span style="">UserType</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'newTypeName'</span>, <span style="color:#A020F0;">'baseTypeName'</span>, typeCheckFunctionHandle<span style="color: #080;">&#41;</span></pre></div></div><p>For example, to create a user-defined type for unsigned eight-bit integers we might use the following code:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">schema.<span style="">UserType</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'uint8'</span>, <span style="color:#A020F0;">'short'</span>, @check_uint8<span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">function</span> check_uint8<span style="color: #080;">&#40;</span>value<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%CHECK_UINT8 Check function for uint8 type definition</span>
    <span style="color: #0000FF;">if</span> <span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>value<span style="color: #080;">&#41;</span> <span style="color: #F0F;">||</span> <span style="color: #080;">&#40;</span>value &lt; <span style="color: #33f;">0</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">||</span> <span style="color: #080;">&#40;</span>value &gt; <span style="color: #33f;">255</span><span style="color: #080;">&#41;</span>
        <span style="color: #0000FF;">error</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Value must be a scalar between 0 and 255'</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div><h3 id="hidden">Hidden properties</h3><p><b>Visible</b> is an <code>'on/off'</code> meta-property that controls whether or not a property is displayed when using the <i><b>get</b></i> function without specifying the property name. Using this mechanism we can easily detect hidden undocumented properties. For example:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">for</span> prop = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>classhandle<span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'Properties'</span><span style="color: #080;">&#41;</span>'
       <span style="color: #0000FF;">if</span> <span style="color: #0000FF;">strcmpi</span><span style="color: #080;">&#40;</span>prop.<span style="">Visible</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span>prop.<span style="">Name</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">end</span>
   <span style="color: #0000FF;">end</span>
&nbsp;
BackingStore
CurrentKey
CurrentModifier
Dithermap
DithermapMode
DoubleBuffer
FixedColors
HelpFcn
HelpTopicMap
MinColormap
JavaFrame
OuterPosition
ActivePositionProperty
PrintTemplate
ExportTemplate
WaitStatus
UseHG2
PixelBounds
HelpTopicKey
Serializable
ApplicationData
Behavior
XLimInclude
YLimInclude
ZLimInclude
CLimInclude
ALimInclude
IncludeRenderer</pre></div></div><p>Note that hidden properties such as these are accessible via <i><b>get/set</b></i> just as any other property. It is simply that they are not displayed when you run <i><b>get(gcf)</b></i> or <i><b>set(gcf)</b></i> &#8211; we need to specifically refer to them by their name: <i><b>get(gcf</b>,&#8217;UseHG2&#8242;)</i>. Many other similar hidden properties are <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/hidden-property/">described in this website</a>.</p><p>You may have noticed that the <b>CaseSensitive</b> meta-property did not show up above when we used <i><b>get</b></i> to show the meta-properties of our <b>Value</b> property. This is because <b>CaseSensitive</b> has its own <b>Visible</b> meta-property set to <code>'off'</code> (i.e., hidden).</p><h3 id="additional">Additional meta-properties</h3><p><b>FactoryValue</b> is used to set an initial value for the property whenever a new <code>simple.object</code> instance is created.</p><p><b>GetFunction</b> and <b>SetFunction</b> were described in last week&#8217;s article, <a
href="http://undocumentedmatlab.com/blog/hierarchical-systems-with-udd/">Creating a UDD Hierarchy</a>.</p><p><b>AccessFlags</b> is a Matlab structure of <code>'on/off'</code> fields that control what happens when the property is accessed:</p><table><tr><th
bgcolor="#D0D0D0">Fieldname</th><th
bgcolor="#D0D0D0">Description</th></tr><tr><td
bgcolor="#E7E7E7">PublicSet</td><td
bgcolor="#E7E7E7">Controls setting the property from code external to the class</td></tr><tr><td
bgcolor="#E7E7E7">PublicGet</td><td
bgcolor="#E7E7E7">Controls reading the property value from code external to the class</td></tr><tr><td
bgcolor="#E7E7E7">PrivateSet</td><td
bgcolor="#E7E7E7">Controls setting the property from internal class methods</td></tr><tr><td
bgcolor="#E7E7E7">PrivateGet</td><td
bgcolor="#E7E7E7">Controls reading the property value from internal class methods</td></tr><tr><td
bgcolor="#E7E7E7">Init</td><td
bgcolor="#E7E7E7">Controls initializing the property using <b>FactoryValue</b> in the class definition file</td></tr><tr><td
bgcolor="#E7E7E7">Default</td><td
bgcolor="#E7E7E7">??? (Undocumented, no examples exist)</td></tr><tr><td
bgcolor="#E7E7E7">Reset</td><td
bgcolor="#E7E7E7">Controls initializing the property using <b>FactoryValue</b> when executing the built-in <i><b>reset</b></i> function</td></tr><tr><td
bgcolor="#E7E7E7">Serialize</td><td
bgcolor="#E7E7E7">Controls whether this object can be serialized</td></tr><tr><td
bgcolor="#E7E7E7">Copy</td><td
bgcolor="#E7E7E7">Controls whether to pass the property&#8217;s current value to a copy</td></tr><tr><td
bgcolor="#E7E7E7">Listener</td><td
bgcolor="#E7E7E7">Controls whether property access events are generated or not</td></tr><tr><td
bgcolor="#E7E7E7">AbortSet</td><td
bgcolor="#E7E7E7">Controls whether property set events are generated when a <i><b>set</b></i> operation will not change the property&#8217;s value</td></tr></table><p>The <b>CaseSensitive</b> meta-property has <b>AccessFlag.Init</b> = <code>'off'</code>. This means that properties added to a class definition file are always case insensitive.</p><p>Another interesting fact is that properties can be abbreviated as long as the abbreviation is unambiguous. Using our <code>simple.object</code> as an example:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; a = simple.<span style="">object</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'a'</span><span style="color: #080;">&#41;</span>;
&gt;&gt; a.<span style="">n</span>  <span style="color: #228B22;">% abbreviation of Name</span>
<span style="color: #0000FF;">ans</span> =
a
&nbsp;
&gt;&gt; a.<span style="">v</span>  <span style="color: #228B22;">% abbreviation of Value</span>
<span style="color: #0000FF;">ans</span> =
    <span style="color: #33f;">0.0000</span></pre></div></div><p>It is considered poor programming practice to use either improperly cased, or abbreviated names when writing code. It is difficult to read, debug and maintain. But show me a Matlab programmer who has never abbreviated <b>Position</b> as &#8216;pos&#8217;&#8230;</p><p><i>Note: for completeness&#8217; sake, read yesterday&#8217;s post on <a
target="_blank" rel="nofollow" href="http://blogs.mathworks.com/loren/2011/03/08/common-design-considerations-for-object-properties/">MCOS properties</a> on Loren&#8217;s blog, written by Dave Foti, author of the original UDD code. Dave&#8217;s post describes the fully-documented MCOS mechanism, which is newer than the undocumented UDD mechanism described here. As mentioned earlier, whereas UDD existed (and still exists) in all Matlab 7 releases, MCOS is only available since R2008a. UDD and MCOS co-exist in Matlab since R2008a. MCOS has definite advantages over UDD, but cannot be used on pre-2008 Matlab releases. Different development and deployment requirements may dictate using either UDD or MCOS (or both). Another pre-R2008a alternative is to use Matlab&#8217;s obsolete yet documented <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/pdf_doc/matlab/pre-version_7.6_oop.pdf">class system</a>.</i></p><p>In the next installment of this series we will take a look at UDD events and listeners.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/' rel='bookmark' title='getundoc &#8211; get undocumented object properties'>getundoc &#8211; get undocumented object properties</a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/' rel='bookmark' title='Displaying hidden handle properties'>Displaying hidden handle properties</a> <small>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles...</small></li><li><a
href='http://undocumentedmatlab.com/blog/borderless-button-used-for-plot-properties/' rel='bookmark' title='Borderless button used for plot properties'>Borderless button used for plot properties</a> <small>A borderless button can be used to add unobtrusive functionality to plot axes...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/udd-properties/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Hierarchical Systems with UDD</title><link>http://undocumentedmatlab.com/blog/hierarchical-systems-with-udd/</link> <comments>http://undocumentedmatlab.com/blog/hierarchical-systems-with-udd/#comments</comments> <pubDate>Wed, 02 Mar 2011 18:00:25 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Guest bloggers]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Donn Shull]]></category> <category><![CDATA[JMI]]></category> <category><![CDATA[schema]]></category> <category><![CDATA[schema.prop]]></category> <category><![CDATA[uitools]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2146</guid> <description><![CDATA[UDD objects can be grouped in structured hierarchies - this article explains how<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/introduction-to-udd/' rel='bookmark' title='Introduction to UDD'>Introduction to UDD</a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li><li><a
href='http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/' rel='bookmark' title='Creating a simple UDD class'>Creating a simple UDD class</a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-events-and-listeners/' rel='bookmark' title='UDD Events and Listeners'>UDD Events and Listeners</a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p><i>Once again I welcome guest blogger <a
target="_blank" rel="nofollow" href="http://aetoolbox.com/">Donn Shull</a>, who continues his multi-part series about Matlab’s undocumented UDD objects.</i></p><p>We have looked at the <a
target="_blank" href="http://undocumentedmatlab.com/blog/introduction-to-udd/">tools for working with UDD classes</a>, and <a
target="_blank" href="http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/">created a simple UDD class</a>. Today I shall show how to create a hierarchy of UDD objects.</p><h3 id="hierarchy">Creating hierarchical structures with UDD objects</h3><p>UDD is the foundation for both Handle Graphics (HG) and Simulink. Both are hierarchical systems. It stands to reason that UDD would offer support for hierarchical structures. It is straightforward to connect UDD objects together into searchable tree structures. All that is necessary is a collection of UDD objects that don&#8217;t have any methods or properties named <code>'connect', 'disconnect', 'up', 'down', 'left', 'right'</code> or <code>'find'</code>.</p><p>We illustrate the technique by creating a hierarchy of <code>simple.object</code>s as shown in the following diagram:</p><p><center><div
class="wp-caption aligncenter" style="width: 210px"><img
alt="Sample UDD objects hierarchy" src="http://UndocumentedMatlab.com/images/UDD_structure.png" title="Sample UDD objects hierarchy" width="200" height="177" /><p
class="wp-caption-text">Sample UDD objects hierarchy</p></div></center></p><p>To begin we create five instances of the <code>simple.object</code> class from the previous article:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Remember that simple.object accepts a name and a value</span>
a = simple.<span style="">object</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'a'</span>, <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
b = simple.<span style="">object</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'b'</span>, <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
c = simple.<span style="">object</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'c'</span>, <span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
d = simple.<span style="">object</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'d'</span>, <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
e = simple.<span style="">object</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'e'</span>, <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>To form the structure we use the <i>connect</i> method. We can use either dot notation or the Matlab syntax:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Dot-notation examples:</span>
a.<span style="">connect</span><span style="color: #080;">&#40;</span>b, <span style="color:#A020F0;">'down'</span><span style="color: #080;">&#41;</span>;
b.<span style="">connect</span><span style="color: #080;">&#40;</span>a, <span style="color:#A020F0;">'up'</span><span style="color: #080;">&#41;</span>;       <span style="color: #228B22;">% alternative to the above</span>
&nbsp;
<span style="color: #228B22;">% Matlab notation examples:</span>
connect<span style="color: #080;">&#40;</span>a, b, <span style="color:#A020F0;">'down'</span><span style="color: #080;">&#41;</span>;
connect<span style="color: #080;">&#40;</span>b, a, <span style="color:#A020F0;">'up'</span><span style="color: #080;">&#41;</span>;      <span style="color: #228B22;">% alternative to the above</span></pre></div></div><p>Next, connect node c into our hierarchy. There are several options here: We can use &#8216;down&#8217; to connect a to c. Or we could use &#8216;up&#8217; to connect c to a. Similarly, we can use either &#8216;left&#8217; or &#8216;right&#8217; to connect b and c. Here&#8217;s one of the many possible ways to create our entire hierarchy:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">b.<span style="">connect</span><span style="color: #080;">&#40;</span>a, <span style="color:#A020F0;">'up'</span><span style="color: #080;">&#41;</span>;
c.<span style="">connect</span><span style="color: #080;">&#40;</span>b, <span style="color:#A020F0;">'left'</span><span style="color: #080;">&#41;</span>;
d.<span style="">connect</span><span style="color: #080;">&#40;</span>b, <span style="color:#A020F0;">'up'</span><span style="color: #080;">&#41;</span>;
e.<span style="">connect</span><span style="color: #080;">&#40;</span>d, <span style="color:#A020F0;">'left'</span><span style="color: #080;">&#41;</span>;</pre></div></div><h3 id="inspecting">Inspecting UDD hierarchy structures</h3><p>We now have our structure and each object knows its connection to other objects. For example, we can inspect b&#8217;s connections as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; b.<span style="">up</span>
<span style="color: #0000FF;">ans</span> =
  Name<span style="color: #F0F;">:</span> a
 Value<span style="color: #F0F;">:</span> <span style="color: #33f;">1.000000</span>
&nbsp;
&gt;&gt; b.<span style="">right</span>
<span style="color: #0000FF;">ans</span> =
  Name<span style="color: #F0F;">:</span> c
 Value<span style="color: #F0F;">:</span> <span style="color: #33f;">0.000000</span>
&nbsp;
&gt;&gt; b.<span style="">down</span>
<span style="color: #0000FF;">ans</span> =
  Name<span style="color: #F0F;">:</span> d
 Value<span style="color: #F0F;">:</span> <span style="color: #33f;">1.000000</span></pre></div></div><p>We can search our structure by using an undocumented form of the built-in <i><b>find</b></i> command. When used with connected UDD structures, <i><b>find</b></i> can be used in the following form:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">objectArray = <span style="color: #0000FF;">find</span><span style="color: #080;">&#40;</span>startingNode, <span style="color:#A020F0;">'property'</span>, <span style="color:#A020F0;">'value'</span>, <span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span></pre></div></div><p>To search from the top of our hierarchy for objects of type <code>simple.object</code> we would use:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">find</span><span style="color: #080;">&#40;</span>a, <span style="color:#A020F0;">'-isa'</span>, <span style="color:#A020F0;">'simple.object'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
        simple.<span style="">object</span><span style="color: #F0F;">:</span> <span style="color: #33f;">5</span>-by-<span style="color: #33f;">1</span>    <span style="color: #228B22;">% a, b, c, d, e</span></pre></div></div><p>Which returns all the objects in our structure, since all of them are <code>simple.object</code>s. If we repeat that command starting at b we would get:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">find</span><span style="color: #080;">&#40;</span>b, <span style="color:#A020F0;">'-isa'</span>, <span style="color:#A020F0;">'simple.object'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
	simple.<span style="">object</span><span style="color: #F0F;">:</span> <span style="color: #33f;">3</span>-by-<span style="color: #33f;">1</span>    <span style="color: #228B22;">% b, d, e</span></pre></div></div><p><i><b>find</b></i> searches the structure downward from the current node. Like many Matlab functions, <i><b>find</b></i> can be used with multiple property value pairs, so if we want to find <code>simple.object</code> objects in our structure with <b>Value</b> property =0, we would use the command:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">find</span><span style="color: #080;">&#40;</span>a, <span style="color:#A020F0;">'-isa'</span>, <span style="color:#A020F0;">'simple.object'</span>, <span style="color:#A020F0;">'Value'</span>, <span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
  Name<span style="color: #F0F;">:</span> c
 Value<span style="color: #F0F;">:</span> <span style="color: #33f;">0.000000</span></pre></div></div><h3 id="visualizing">Visualizing a UDD hierarchy</h3><p>Hierarchical structures are also known as tree structures. Matlab has an undocumented function for visualizing and working with trees namely <i><b>uitree</b></i>. Yair has described <i><b>uitree</b></i> in a <a
target="_blank" href="http://UndocumentedMatlab.com/blog/uitree/">series of articles</a>. Rather than following the techniques in shown in Yair&#8217;s articles, we are going to use a different method that will allow us to introduce the following important techniques for working with UDD objects:</p><ul><li>Subclassing, building your class on the foundation of a parent class</li><li>Overloading properties and methods of the superclass</li><li>Using meta-properties <b>GetfFunction</b> and <b>SetFunction</b></li></ul><p>Because the steps shown below will subclass an HG class, they will modify our <code>simple.object</code> class and probably make it unsuitable for general use. Yair has shown that <i><b>uitree</b></i> is ready made for displaying HG trees and we saw above that HG is a UDD system. We will use the technique from <code>uitools.uibuttongroup</code> to make our <code>simple.object</code> class a subclass of the HG class <code>hg.uipanel</code>. Modify the class definition file as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% class definition</span>
superPackage = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'hg'</span><span style="color: #080;">&#41;</span>;
superClass = findclass<span style="color: #080;">&#40;</span>superPackage, <span style="color:#A020F0;">'uipanel'</span><span style="color: #080;">&#41;</span>;
simpleClass = schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#40;</span>simplePackage, <span style="color:#A020F0;">'object'</span>,superClass<span style="color: #080;">&#41;</span>;</pre></div></div><p>Now we can either issue the <i><b>clear classes</b></i> command or restart Matlab and then recreate our structure. The first thing that you will notice is that when we create the first <code>simple.object</code> that a figure is also created. This is expected and is the reason that this technique is not useful in general. We will however use this figure to display our structure with the following commands:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">t = uitree<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'v0'</span>, <span style="color:#A020F0;">'root'</span>, a<span style="color: #080;">&#41;</span>;  <span style="color: #0000FF;">drawnow</span>;
t.<span style="">expand</span><span style="color: #080;">&#40;</span>t.<span style="">getRoot</span><span style="color: #080;">&#41;</span>;  <span style="color: #0000FF;">drawnow</span>;
t.<span style="">expand</span><span style="color: #080;">&#40;</span>t.<span style="">getRoot</span>.<span style="">getFirstChild</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 451px"><img
alt="Simple structure presented in a Matlab uitree" src="http://UndocumentedMatlab.com/images/UDD_uitree_1.png" title="Simple structure presented in a Matlab uitree" width="441" height="189" /><p
class="wp-caption-text">Simple structure presented in a Matlab <i><b>uitree</b></i></p></div></center></p><p>The label on each of our objects is &#8216;uipanel&#8217; and this is probably not what we want. If we inspect our object or its <code>hg.uipanel</code> super-class (note: this would be a great time to use Yair&#8217;s <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object"><i><b>uiinspect</b></i> utility</a>), we can see there is a <b>Type</b> property that has a value of &#8216;uipanel&#8217;. Unfortunately this property is read-only, so we cannot change it. We can however overload it by placing a <i><b>schema.prop</b></i> in our class definition named <b>Type</b>. This will allow us to overload or replace the parent&#8217;s <b>Type</b> property with our own definition:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">p = schema.<span style="">prop</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'Type'</span>, <span style="color:#A020F0;">'string'</span><span style="color: #080;">&#41;</span>;
p.<span style="">FactoryValue</span> = <span style="color:#A020F0;">'simple.object'</span>;</pre></div></div><p>Once again, issue the <i><b>clear classes</b></i> command or restart Matlab, then recreate our structure. Our tree now has each node labeled with the &#8216;simple.object&#8217; label:</p><p><center><div
class="wp-caption aligncenter" style="width: 451px"><img
alt="Corrected node names for our UDD structure" src="http://UndocumentedMatlab.com/images/UDD_uitree_2.png" title="Corrected node names for our UDD structure" width="441" height="189" /><p
class="wp-caption-text">Corrected node names for our UDD structure</p></div></center></p><p>This is a little more descriptive but what would really be nice is if we could label each node with the value of the <b>Name</b> property. As luck would have it, we can do just that. When we add a property to a UDD class we are adding an object of type <code>schema.prop</code>. So our properties have their own properties and methods (so-called <i>meta-data</i>). We are going to set the <b>GetFunction</b> property of our <b>Type</b> property. <b>GetFunction</b> holds a handle of the function to be called whenever the property is accessed:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">p = schema.<span style="">prop</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'Type'</span>, <span style="color:#A020F0;">'string'</span><span style="color: #080;">&#41;</span>;
p.<span style="">GetFunction</span> = @getType;</pre></div></div><p>The prototype for the function that <b>GetFunction</b> references has three inputs and one output: The inputs are the handle of the object possessing the property, the value of that property, and the property object. The output is the value that will be supplied when the property is accessed. So our <b>GetFunction</b> can be written to supply the value of the <b>Name</b> property whenever the <b>Type</b> property value is being read:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> propVal = getType<span style="color: #080;">&#40;</span>self, value, prop<span style="color: #080;">&#41;</span>
   propVal = self.<span style="">Name</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>Alternately, as a single one-liner in the schema definition file:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">p.<span style="">GetFunction</span> = @<span style="color: #080;">&#40;</span>self,value,prop<span style="color: #080;">&#41;</span> self.<span style="">Name</span>;</pre></div></div><p>Similarly, there is a corresponding <b>SetFunction</b> that enables us to intercept changes to a property&#8217;s value and possibly disallow invalid values.</p><p>With these changes when we recreate our <i><b>uitree</b></i> we obtain:</p><p><center><div
class="wp-caption aligncenter" style="width: 451px"><img
alt="Overloaded property GetFunction" src="http://UndocumentedMatlab.com/images/UDD_uitree_3.png" title="Overloaded property GetFunction" width="441" height="189" /><p
class="wp-caption-text">Overloaded property <b>GetFunction</b></p></div></center></p><h3 id="java">A Java class for UDD trees</h3><p>We will have more to say about the relationship between UDD and Java in a future article. For now we simply note that the <code>com.mathworks.jmi.bean.UDDObjectTreeModel</code> class in the <a
target="_blank" href="http://UndocumentedMatlab.com/blog/jmi-java-to-matlab-interface/">JMI package</a> provides some UDD tree navigation helper functions. Methods include <i>getChild, getChildCount, getIndexOfChild</i> and <i>getPathToRoot</i>. The <code>UDDObjectTreeModel</code> constructor requires one argument, an instance of your UDD tree root node:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Create a UDD tree-model instance</span>
&gt;&gt; uddTreeModel = com.<span style="">mathworks</span>.<span style="">jmi</span>.<span style="">bean</span>.<span style="">UDDObjectTreeModel</span><span style="color: #080;">&#40;</span>a<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Get index of child e and its parent b:</span>
&gt;&gt; childIndex = uddTreeModel.<span style="">getIndexOfChild</span><span style="color: #080;">&#40;</span>b, e<span style="color: #080;">&#41;</span>
childIndex =
     <span style="color: #33f;">1</span>
&nbsp;
<span style="color: #228B22;">% Get the root's first child (#0):</span>
&gt;&gt; child0 = uddTreeModel.<span style="">getChild</span><span style="color: #080;">&#40;</span>a, <span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>
child0 =
  Name<span style="color: #F0F;">:</span> b
 Value<span style="color: #F0F;">:</span> <span style="color: #33f;">1.000000</span>
&nbsp;
<span style="color: #228B22;">% Get the path from node e to the root:</span>
&gt;&gt; path2root = uddTreeModel.<span style="">getPathToRoot</span><span style="color: #080;">&#40;</span>e<span style="color: #080;">&#41;</span>
path2root =
com.<span style="">mathworks</span>.<span style="">jmi</span>.<span style="">bean</span>.<span style="">UDDObject</span><span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span><span style="color: #F0F;">:</span>
    <span style="color: #080;">&#91;</span>simple_objectBeanAdapter2<span style="color: #080;">&#93;</span>      <span style="color: #228B22;">% &lt;= a</span>
    <span style="color: #080;">&#91;</span>simple_objectBeanAdapter2<span style="color: #080;">&#93;</span>      <span style="color: #228B22;">% &lt;= b</span>
    <span style="color: #080;">&#91;</span>simple_objectBeanAdapter2<span style="color: #080;">&#93;</span>      <span style="color: #228B22;">% &lt;= e</span>
&nbsp;
&gt;&gt; path2root<span style="color: #080;">&#40;</span><span style="color: #33f;">3</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
  Name<span style="color: #F0F;">:</span> e
 Value<span style="color: #F0F;">:</span> <span style="color: #33f;">1.000000</span></pre></div></div><p>We touched on a few of the things that you can do by modifying the properties of a <code>schema.prop</code> in this article. In the following article we will take a more detailed look at this essential class.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/introduction-to-udd/' rel='bookmark' title='Introduction to UDD'>Introduction to UDD</a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li><li><a
href='http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/' rel='bookmark' title='Creating a simple UDD class'>Creating a simple UDD class</a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-events-and-listeners/' rel='bookmark' title='UDD Events and Listeners'>UDD Events and Listeners</a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/hierarchical-systems-with-udd/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Creating a simple UDD class</title><link>http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/</link> <comments>http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/#comments</comments> <pubDate>Wed, 23 Feb 2011 17:29:05 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Guest bloggers]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Donn Shull]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema]]></category> <category><![CDATA[schema.class]]></category> <category><![CDATA[schema.prop]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2130</guid> <description><![CDATA[This article explains how to create and test custom UDD packages, classes and objects<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/extending-a-java-class-with-udd/' rel='bookmark' title='Extending a Java class with UDD'>Extending a Java class with UDD</a> <small>Java classes can easily be extended in Matlab, using pure Matlab code. ...</small></li><li><a
href='http://undocumentedmatlab.com/blog/introduction-to-udd/' rel='bookmark' title='Introduction to UDD'>Introduction to UDD</a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-events-and-listeners/' rel='bookmark' title='UDD Events and Listeners'>UDD Events and Listeners</a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p><i>Once again I welcome guest blogger <a
target="_blank" rel="nofollow" href="http://aetoolbox.com/">Donn Shull</a>, who continues his multi-part series about Matlab&#8217;s undocumented UDD objects.</i></p><h3 id="package">Creating a new UDD package</h3><p>To illustrate the construction of UDD classes with Matlab m-code, let&#8217;s create a simple class belonging to a new simple package. Our class will have two properties: a <b>Name</b> property of type string, and a <b>Value</b> property of type double. This class will have two methods that will illustrate overloading the built-in <i><b>disp</b></i> function, and using a <i>dialog</i> method to present a GUI. Our class will also have one event, to demonstrate UDD event handling.</p><p>To create this simple UDD class we need two directories and five m-files (downloadable <a
href="http://UndocumentedMatlab.com/files/simple.zip">here</a>): The parent directory needs to be a directory on the Matlab path. A subdirectory of the parent directory is named with the symbol @ followed by our UDD package name &#8211; this is the package directory. In this example, the subdirectory is called @simple.</p><p>Within the @simple directory, place a file named <i>schema.m</i>, which is the package definition file. This is a very simple file, that merely calls <i><b>schema.package</b></i> to create a new package called &#8216;simple&#8217;:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> schema<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%SCHEMA simple package definition function.</span>
   schema.<span style="">package</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'simple'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>If you place additional m-files in the package directory they will be called package function files. Those files will have package scope and can be accessed with the notation <code>packagename.functionname</code>. We will not use package functions in this example, so we will only have the schema.m file shown above.</p><h3 id="class">Creating a new UDD class</h3><p>Next, create another subdirectory beneath @simple, named with an @ symbol followed by the UDD class name. In this example we will create the directory @object (i.e., /@simple/@object/). We place four m-files in this directory:</p><p>The first file is yet another schema.m file, which is the class-definition file:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> schema<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%SCHEMA  simple.object class definition function.</span>
&nbsp;
   <span style="color: #228B22;">% Get a handle to the 'simple' package</span>
   simplePackage = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'simple'</span><span style="color: #080;">&#41;</span>;
&nbsp;
   <span style="color: #228B22;">% Create a base UDD object</span>
   simpleClass = schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#40;</span>simplePackage, <span style="color:#A020F0;">'object'</span><span style="color: #080;">&#41;</span>;
&nbsp;
   <span style="color: #228B22;">% Define the class methods:</span>
&nbsp;
   <span style="color: #228B22;">% dialog.m method</span>
   m = schema.<span style="">method</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'dialog'</span><span style="color: #080;">&#41;</span>;
   s = m.<span style="">Signature</span>;
   s.<span style="color: #0000FF;">varargin</span>    = <span style="color:#A020F0;">'off'</span>;
   s.<span style="">InputTypes</span>  = <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'handle'</span><span style="color: #080;">&#125;</span>;
   s.<span style="">OutputTypes</span> = <span style="color: #080;">&#123;</span><span style="color: #080;">&#125;</span>;
&nbsp;
   <span style="color: #228B22;">% disp.m method</span>
   m = schema.<span style="">method</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'disp'</span><span style="color: #080;">&#41;</span>;
   s = m.<span style="">Signature</span>;
   s.<span style="color: #0000FF;">varargin</span>    = <span style="color:#A020F0;">'off'</span>;
   s.<span style="">InputTypes</span>  = <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'handle'</span><span style="color: #080;">&#125;</span>;
   s.<span style="">OutputTypes</span> = <span style="color: #080;">&#123;</span><span style="color: #080;">&#125;</span>;
&nbsp;
   <span style="color: #228B22;">% Define the class properties:</span>
   schema.<span style="">prop</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'Name'</span>, <span style="color:#A020F0;">'string'</span><span style="color: #080;">&#41;</span>;
   schema.<span style="">prop</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'Value'</span>, <span style="color:#A020F0;">'double'</span><span style="color: #080;">&#41;</span>;
&nbsp;
   <span style="color: #228B22;">% Define the class events:</span>
   schema.<span style="">event</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'simpleEvent'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>Here, we used the built-in <i><b>findpackage</b></i> function to identify our base package (<code>simple</code>). Then we used <i><b>schema.class</b></i> to define a new class &#8216;object&#8217; within that base package. We next defined two class methods, two properties and finally an event.</p><h3 id="methods">Defining class methods</h3><p>It is not mandatory to define the method signatures as we have done in our class definition file. If you omit the method signature definitions, Matlab will automatically generate default signatures that will actually work in most applications. However, I believe that it is bad practice to omit the method signature definitions in a class definition file, and there are cases where your classes will not work as you have intended if you omit them.</p><p>Now, place a file named object.m in the @object directory. This file contains the class constructor method, which is executed whenever a new instance object of the <code>simple.object</code> class is created:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> simpleObject = object<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%OBJECT constructor for the simple.object class</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   SIMPLEOBJECT = OBJECT(NAME, VALUE) creates an instance of the</span>
<span style="color: #228B22;">%   simple.object class with the Name property set to NAME and the</span>
<span style="color: #228B22;">%   Value property set VALUE</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   SIMPLEOBJECT = OBJECT(NAME) creates an instance of the simple.object</span>
<span style="color: #228B22;">%   class with the Name property set to NAME. The Value property will be</span>
<span style="color: #228B22;">%   given the default value of 0.</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   SIMPLEOBJECT = OBJECT creates an instance of the simple.object class</span>
<span style="color: #228B22;">%   and executes the simple.object dialog method to open a GUI for editing</span>
<span style="color: #228B22;">%   the Name and Value properties.</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   INPUTS:</span>
<span style="color: #228B22;">%       NAME          : string</span>
<span style="color: #228B22;">%       VALUE         : double</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   OUTPUTS:</span>
<span style="color: #228B22;">%       SIMPLEOBJECT  : simple.object instance</span>
   simpleObject = simple.<span style="">object</span>;
   <span style="color: #0000FF;">switch</span> <span style="color: #0000FF;">nargin</span>
      <span style="color: #0000FF;">case</span> <span style="color: #33f;">0</span>
         simpleObject.<span style="color: #0000FF;">dialog</span>;
      <span style="color: #0000FF;">case</span> <span style="color: #33f;">1</span>
         simpleObject.<span style="">Name</span> = name;
      <span style="color: #0000FF;">case</span> <span style="color: #33f;">2</span>
         simpleObject.<span style="">Name</span> = name;
         simpleObject.<span style="">Value</span> = value;
   <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div><p>The two other m-files in the @object directory will be our class methods &#8211; a single file for each method. In our case they are disp.m and dialog.m:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span>self<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%DISP overloaded object disp method</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   DISP(SELF) or SELF.DISP uses the MATLAB builtin DISP function</span>
<span style="color: #228B22;">%   to display the Name and Value properties of the object.</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   INPUTS:</span>
<span style="color: #228B22;">%       SELF  : simple.object instance</span>
   <span style="color: #0000FF;">builtin</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'disp'</span>, <span style="color: #0000FF;">sprintf</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'  Name: %s\n Value: %f'</span>, self.<span style="">Name</span>, self.<span style="">Value</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
   <span style="color: #228B22;">%Alternative: fprintf('\n  Name: %s\n Value: %f', self.Name, self.Value));</span>
<span style="color: #0000FF;">end</span></pre></div></div><p>And the dialog method (in dialog.m):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> <span style="color: #0000FF;">dialog</span><span style="color: #080;">&#40;</span>self<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%DIALOG dialog method for simple.object for use by openvar</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   DIALOG(SELF) or SELF.DIALOG where self is the name of the simple.object</span>
<span style="color: #228B22;">%   instance opens a gui to edit the Name and Value properties of self.</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   INPUTS:</span>
<span style="color: #228B22;">%       SELF  : simple.object</span>
   dlgValues = <span style="color: #0000FF;">inputdlg</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#123;</span><span style="color:#A020F0;">'Name:'</span>, <span style="color:#A020F0;">'Value:'</span><span style="color: #080;">&#125;</span>, <span style="color:#A020F0;">'simple.object'</span>, <span style="color: #33f;">1</span>, <span style="color: #080;">&#123;</span>self.<span style="">Name</span>, <span style="color: #0000FF;">mat2str</span><span style="color: #080;">&#40;</span>self.<span style="">Value</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">if</span> ~<span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>dlgValues<span style="color: #080;">&#41;</span>
      self.<span style="">Name</span> = dlgValues<span style="color: #080;">&#123;</span><span style="color: #33f;">1</span><span style="color: #080;">&#125;</span>;
      self.<span style="">Value</span> = <span style="color: #0000FF;">eval</span><span style="color: #080;">&#40;</span>dlgValues<span style="color: #080;">&#123;</span><span style="color: #33f;">2</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div><h3 id="testing">Testing our new class</h3><p>Now let&#8217;s test our new class by creating an instance without using any input arguments</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">a = simple.<span style="">object</span></pre></div></div><p>This calls the object&#8217;s constructor method, which launches the input dialog GUI:<br
/><center><div
class="wp-caption aligncenter" style="width: 191px"><img
alt="UDD simple class GUI" src="http://UndocumentedMatlab.com/images/UDD_simple_object_1.jpg" title="UDD simple class GUI" width="181" height="163" /><p
class="wp-caption-text">UDD simple class GUI</p></div></center></p><p>Note the default empty string value for the <b>Name</b> property, and the default zero value for the <b>Value</b> property. In one of the following articles I will show how to control property values. For now let&#8217;s assign &#8216;a&#8217; to <b>Name</b> and 1 to <b>Value</b> using the GUI. Selecting OK updates our object and closes the GUI. Matlab then calls the object&#8217;s <i>disp</i> method to display our object in the command window:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">a = 
  Name<span style="color: #F0F;">:</span> a
 Value<span style="color: #F0F;">:</span> <span style="color: #33f;">1.000000</span></pre></div></div><p>We can reopen our object&#8217;s GUI using three methods: The most obvious is to invoke the <i>dialog</i> method using <code>a.dialog</code> or <code>dialog(a)</code>. Alternately, double click on a in the workspace explorer window &#8211; Matlab will automatically call the built-in <i><b>openvar</b></i> function with the variable name and value as arguments. Which leads us to the third method &#8211; simply call <i><b>openvar</b>(&#8216;a&#8217;, a)</i> directly:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Alternatives for programmatically displaying the GUI</span>
a.<span style="color: #0000FF;">dialog</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% or simply: a.dialog</span>
<span style="color: #0000FF;">dialog</span><span style="color: #080;">&#40;</span>a<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">openvar</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'a'</span>,a<span style="color: #080;">&#41;</span>;</pre></div></div><h3 id="help">Accessing UDD help</h3><p>You may have noticed that in our constructor and method files we have included help text. This is good practice for all Matlab files in general, and UDD is no exception. We can access the UDD class help as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="text" style="font-family:monospace;">&gt; help simple.object
 OBJECT constructor for the simple.object class
&nbsp;
    SIMPLEOBJECT = OBJECT(NAME, VALUE) creates an instance of the 
    simple.object class with the Name property set to NAME and the 
    Value property set VALUE
&nbsp;
    SIMPLEOBJECT = OBJECT(NAME) creates an instance of the simple.object
    class with the Name property set to NAME. The Value property will be
    given the default value of 0.
&nbsp;
    SIMPLEOBJECT = OBJECT creates an instance of the simple.object class 
    and executes the simple.object dialog method to open a GUI for editing
    the Name and Value properties.
&nbsp;
    INPUTS:
        NAME          : string
        VALUE         : double
&nbsp;
    OUTPUTS:
        SIMPLEOBJECT  : simple.object instance
&nbsp;
&gt;&gt; help simple.object.disp
 DISP overloaded object disp method
&nbsp;
    DISP(SELF) or SELF.DISP uses the MATLAB builtin DISP function
    to display the Name and Value properties of the object.
&nbsp;
    INPUTS:
        SELF  : simple.object instance</pre></div></div><p>One of the best ways to learn how Matlab works is to examine code written by the Matlab development team. <i><b>openvar</b></i> is a good example: By looking at it we can see that if a variable is a <i><b>handle</b></i> object and is opaque, then <i><b>openvar</b></i> will check to see if it has a <i>dialog</i> method. If so, it will use that to open the variable for editing. With this information we can guess that MCOS, UDD and even java objects can all launch their own dialog editors simply by having an appropriate <i>dialog</i> method.</p><p>An excellent source of UDD information is available in the Matlab toolbox folders. The base Matlab toolbox contains sixteen different UDD packages to explore. Yummy!</p><p>In the next article of this UDD series we will look at creating hierarchical structures using our <code>simple.object</code> and a unique UDD method.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/extending-a-java-class-with-udd/' rel='bookmark' title='Extending a Java class with UDD'>Extending a Java class with UDD</a> <small>Java classes can easily be extended in Matlab, using pure Matlab code. ...</small></li><li><a
href='http://undocumentedmatlab.com/blog/introduction-to-udd/' rel='bookmark' title='Introduction to UDD'>Introduction to UDD</a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-events-and-listeners/' rel='bookmark' title='UDD Events and Listeners'>UDD Events and Listeners</a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Introduction to UDD</title><link>http://undocumentedmatlab.com/blog/introduction-to-udd/</link> <comments>http://undocumentedmatlab.com/blog/introduction-to-udd/#comments</comments> <pubDate>Wed, 16 Feb 2011 18:00:09 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Guest bloggers]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Listeners]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Donn Shull]]></category> <category><![CDATA[Internal component]]></category> <category><![CDATA[Listener]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema]]></category> <category><![CDATA[schema.class]]></category> <category><![CDATA[schema.prop]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2036</guid> <description><![CDATA[UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/' rel='bookmark' title='Creating a simple UDD class'>Creating a simple UDD class</a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-events-and-listeners/' rel='bookmark' title='UDD Events and Listeners'>UDD Events and Listeners</a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/hierarchical-systems-with-udd/' rel='bookmark' title='Hierarchical Systems with UDD'>Hierarchical Systems with UDD</a> <small>UDD objects can be grouped in structured hierarchies - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/new-information-on-hg2/' rel='bookmark' title='New information on HG2'>New information on HG2</a> <small>More information on Matlab's new HG2 object-oriented handle-graphics system...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p><i>I would like to welcome guest blogger <a
target="_blank" rel="nofollow" href="http://aetoolbox.com/">Donn Shull</a>. Donn will present a series of articles about UDD classes and objects, on which many undocumented Matlab features and functions are based.</i></p><h3 id="Background">Background on UDD</h3><p>Matlab has used objects for a long time. In R8 (Matlab 5.0), their first user accessible class system was introduced. Andy Register wrote a <a
target="_blank" rel="nofollow" href="http://www.scitechpub.com/catalog/product_info.php?products_id=386">detailed reference</a> on using this system. Although that original system is obsolete, it is still available in R24 (R2010b).</p><p>UDD objects (also referred to as <i>schema</i> objects) were introduced with R12 (Matlab 6.0). UDD has been a foundation platform for a number of core Matlab technologies. MathWorks have consistently maintained that UDD is only meant for internal development and not for Matlab users. So, while UDD has no formal documentation, there are plenty of examples and tools to help us learn about it.</p><p>It is somewhat odd that despite Matlab&#8217;s new object-oriented system (<a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/matlab_oop/bri1rtu.html">MCOS</a>)&#8217;s introduction 3 years ago, and the <a
target="_blank" href="http://UndocumentedMatlab.com/blog/tag/hg2/">ongoing concurrent development of HG2</a> classes, the older-technology UDD is still being actively developed, as evidenced by the increasing number of UDD classes in recent releases. More background on the differences between these different sets of classes can be found <a
target="_blank" href="http://UndocumentedMatlab.com/blog/new-information-on-hg2/">here</a>.</p><h3 id="WhyBother">Why should we bother learning UDD?</h3><p>There are some things to consider before deciding if you want to spend the time to learn about the UDD class system:</p><h4 id="Pros">The case against studying UDD classes</h4><ul><li>There is no documentation from The MathWorks for these classes</li><li>You will not get any help from The MathWorks in applying these classes</li><li>The UDD system is now more than a decade old and may be phased out in future Matlab releases (perhaps in HG2?)</li></ul><h4 id="Cons">The case for studying UDD classes</h4><ul><li>UDD is currently the foundation of handle graphics, Java integration, COM, and Simulink</li><li>The m code versions of UDD may be considered a forerunner of the newer MCOS class system</li><li>To avoid memory leaks when using Callbacks in GUI applications you currently need to use UDD</li><li>UDD techniques facilitate Matlab interaction with Java GUIs</li><li>UDD directly supports the Matlab style method invocation as well as dot notation for methods without the need to write subsasgn and subsref routines</li></ul><h3 id="Tools">Tools for Learning about UDD</h3><p>We start by describing some undocumented Matlab tools that will help us investigate and understand UDD classes.</p><ul><li><i><b>findpackage</b></i> &#8211; All UDD Classes are defined as members of a package. findpackage takes the package name as an input argument and returns a schema.package object which provides information about the package</li><li><i><b>findclass</b></i> &#8211; This method of the schema.package object returns a schema.class object of the named class if the class exists in the package</li><li><i><b>classhandle</b></i> &#8211; For a given UDD object <i><b>classhandle</b></i> returns a schema.class object with information about the class. <i><b>classhandle</b></i> and <i><b>findclass</b></i> are two ways of getting the same information about a UDD class. <i><b>findclass</b></i> works with a <i><b>schema.package</b></i> object and a class name and does not require an instance of the class. <i><b>classhandle</b></i> works with an instance of a class</li><li><i><b>findprop</b></i> &#8211; This method of the schema.class object returns a schema.prop object which contains information about the named property</li><li><i><b>findevent</b></i> &#8211; This method of the schema.class object returns a schema.prop object which contains information about the named event</li><li><i><b>handle</b></i> &#8211; handle is a multifaceted and unique term for The MathWorks. There are both UDD and MCOS handle classes. There is a UDD handle package. In terms of the tools we need, <i><b>handle</b></i> is also an undocumented function which converts a numeric handle into a UDD handle object. Depending on your background you may want to think of <i><b>handle</b></i> as a cast operator which casts a numeric handle into a UDD object.</li><li><i><b>methods</b></i> &#8211; This is used to display the methods of an object</li><li><i><b>methodsview</b></i> &#8211; Provides a graphic display of an objects methods</li><li><a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object"><i><b>uiinspect</b></i></a> &#8211; Yair Altman&#8217;s object inspection tool, which can be used for COM, Java and Matlab classes (<i><b>uiinspect</b> will be described in a separate article in the near future</i>).</li></ul><p>Before we apply these tools we need to discuss the basic structure of UDD classes. Let&#8217;s compare them with the newer, well documented MCOS classes:</p><p>MCOS classes can be defined simply as a standalone class or scoped by placing the class in a package or a hierarchy of packages. With UDD, all classes must be defined in a package. UDD Packages are not hierarchical so a UDD package may not contain other packages. UDD classes can always be instantiated with syntax of packageName.className. By default MCOS classes are value classes. With MCOS you can subclass the handle class to create handle classes. UDD classes are handle classes by default, but it is possible to create UDD value classes.</p><h3 id="Exploring">Exploring some important built-in UDD Classes</h3><p>The current versions of Matlab include a number of built-in UDD packages. We will use our new tools to see what we can learn about these packages. Let us begin by inspecting the two packages that form the basis of the UDD class system.</p><h4 id="schema">The schema package</h4><p>The built-in schema package contains the classes for creating user written UDD classes. It also is used to provide meta information about UDD classes. Using <i><b>findpackage</b></i> we will obtain a schema.package object for the schema package and then use it obtain information about the classes it contains:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; pkg = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'schema'</span><span style="color: #080;">&#41;</span>
pkg =
        schema.<span style="">package</span>
&nbsp;
&gt;&gt; pkg.<span style="color: #0000FF;">get</span>
               Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'schema'</span>
    DefaultDatabase<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 handle.<span style="">Database</span><span style="color: #080;">&#93;</span>
            Classes<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>9x1 schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#93;</span>
          Functions<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>0x1 handle<span style="color: #080;">&#93;</span>
        JavaPackage<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
         Documented<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span></pre></div></div><p>Note that here we have used the dot-notation pkg.<i><b>get</b></i> &#8211; we could also have used the Matlab notation <i><b>get</b>(pkg)</i> instead.</p><p>We have now learned that that there are nine classes in the schema package. The information about them in a schema package&#8217;s <b>Classes</b> property. To see the information about individual classes we inspect this property:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; pkg.<span style="">Classes</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>.<span style="color: #0000FF;">get</span>
               Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'class'</span>
            Package<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 schema.<span style="">package</span><span style="color: #080;">&#93;</span>
        Description<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
        AccessFlags<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
             <span style="color: #0000FF;">Global</span><span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
             Handle<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
       Superclasses<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>0x1 handle<span style="color: #080;">&#93;</span>
    SuperiorClasses<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
    InferiorClasses<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
            <span style="color: #0000FF;">Methods</span><span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>4x1 schema.<span style="">method</span><span style="color: #080;">&#93;</span>
         Properties<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>13x1 schema.<span style="">prop</span><span style="color: #080;">&#93;</span>
             Events<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
     JavaInterfaces<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span></pre></div></div><p>Not surprisingly, the first class in the schema.package is &#8216;class&#8217; itself. Here we can see that schema.class has 4 methods and 13 properties. We can also see that the schema.class objects have a <b>Name</b> property. Let&#8217;s use that information to list all the classes in the schema package:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; names = <span style="color: #0000FF;">cell</span><span style="color: #080;">&#40;</span>numel<span style="color: #080;">&#40;</span>pkg.<span style="">Classes</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">for</span> index = <span style="color: #33f;">1</span><span style="color: #F0F;">:</span>numel<span style="color: #080;">&#40;</span>names<span style="color: #080;">&#41;</span>, names<span style="color: #080;">&#123;</span>index<span style="color: #080;">&#125;</span> = pkg.<span style="">Classes</span><span style="color: #080;">&#40;</span>index<span style="color: #080;">&#41;</span>.<span style="">Name</span>; <span style="color: #0000FF;">end</span>;
&gt;&gt; names
names =
    <span style="color:#A020F0;">'class'</span>
    <span style="color:#A020F0;">'method'</span>
    <span style="color:#A020F0;">'signature'</span>
    <span style="color:#A020F0;">'package'</span>
    <span style="color:#A020F0;">'event'</span>
    <span style="color:#A020F0;">'prop'</span>
    <span style="color:#A020F0;">'type'</span>
    <span style="color:#A020F0;">'EnumType'</span>
    <span style="color:#A020F0;">'UserType'</span></pre></div></div><p>These are the base classes for the UDD package schema. To illustrate a different way to get information, let&#8217;s use the <i><b>findclass</b></i> method of schema.package to get information about the schema.prop class:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; p = findclass<span style="color: #080;">&#40;</span>pkg, <span style="color:#A020F0;">'prop'</span><span style="color: #080;">&#41;</span>
p =
        schema.<span style="color: #0000FF;">class</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>p<span style="color: #080;">&#41;</span>
               Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'prop'</span>
            Package<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 schema.<span style="">package</span><span style="color: #080;">&#93;</span>
        Description<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
        AccessFlags<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
             <span style="color: #0000FF;">Global</span><span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
             Handle<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
       Superclasses<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>0x1 handle<span style="color: #080;">&#93;</span>
    SuperiorClasses<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
    InferiorClasses<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
            <span style="color: #0000FF;">Methods</span><span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>2x1 schema.<span style="">method</span><span style="color: #080;">&#93;</span>
         Properties<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>9x1 schema.<span style="">prop</span><span style="color: #080;">&#93;</span>
             Events<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
     JavaInterfaces<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span></pre></div></div><h4 id="handle">The handle package</h4><p>The second basic UDD package is the handle package. Handle holds a special place in Matlab and has multiple meanings: Handle is a type of Matlab object that is passed by reference; <i><b>handle</b></i> is a function which converts a numeric handle to an object; handle is an abstract object in the new MCOS class system and handle is also a UDD package as well as the default type for UDD objects.</p><p>There is an interesting connection between UDD and MCOS that involves handle. In Matlab releases R12 through R2007b, the UDD handle package had up to 12 classes and did not have any package functions (package functions are functions which are scoped to a package; their calling syntax is [outputs] = packageName.<i>functionName(inputs)</i>).</p><p>Beginning with the formal introduction of MCOS in R2008a, the abstract MCOS class handle was introduced. The MCOS handle class has 12 methods. It also turns out that beginning with R2008a, the UDD handle package has 12 package functions which are the MCOS handle methods.</p><p>The 12 UDD classes in the handle package fall into two groups: The database and transaction classes work with the schema.package to provide a UDD stack mechanism; the listener and family of EventData classes work with schema.event to provide the UDD event mechanism:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; pkg = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'handle'</span><span style="color: #080;">&#41;</span>
pkg =
        schema.<span style="">package</span>
&nbsp;
&gt;&gt; pkg.<span style="color: #0000FF;">get</span>
               Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'handle'</span>
    DefaultDatabase<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 handle.<span style="">Database</span><span style="color: #080;">&#93;</span>
            Classes<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>12x1 schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#93;</span>
          Functions<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>12x1 schema.<span style="">method</span><span style="color: #080;">&#93;</span>
        JavaPackage<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
         Documented<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
&nbsp;
&gt;&gt; names = <span style="color: #0000FF;">cell</span><span style="color: #080;">&#40;</span>numel<span style="color: #080;">&#40;</span>pkg.<span style="">Classes</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">for</span> index = <span style="color: #33f;">1</span><span style="color: #F0F;">:</span>numel<span style="color: #080;">&#40;</span>names<span style="color: #080;">&#41;</span>, names<span style="color: #080;">&#123;</span>index<span style="color: #080;">&#125;</span> = pkg.<span style="">Classes</span><span style="color: #080;">&#40;</span>index<span style="color: #080;">&#41;</span>.<span style="">Name</span>; <span style="color: #0000FF;">end</span>
&gt;&gt; names
names =
    <span style="color:#A020F0;">'Operation'</span>
    <span style="color:#A020F0;">'transaction'</span>
    <span style="color:#A020F0;">'Database'</span>
    <span style="color:#A020F0;">'EventData'</span>
    <span style="color:#A020F0;">'ClassEventData'</span>
    <span style="color:#A020F0;">'ChildEventData'</span>
    <span style="color:#A020F0;">'ParentEventData'</span>
    <span style="color:#A020F0;">'PropertyEventData'</span>
    <span style="color:#A020F0;">'PropertySetEventData'</span>
    <span style="color:#A020F0;">'listener'</span>
    <span style="color:#A020F0;">'JavaEventData'</span>
    <span style="color:#A020F0;">'subreference__'</span></pre></div></div><h4 id="hg">The hg package</h4><p>Arguably the most important UDD package in Matlab is the handle graphics package hg. Among the built-in UDD packages, hg is unique in several respects. As Matlab has evolved from R12 through R2011a, the number of default classes in the hg package has nearly doubled going from 17 classes to 30 (UDD has a mechanism for automatically defining additional classes as needed during run-time).</p><p>The hg package contains a mixture of Global and non Global classes. These classes return a numeric handle, unless they have been created using package scope. The uitools m-file package provides a great example of extending built-in UDD classes with user written m-file UDD classes.</p><p>The UDD class for a Handle-Graphics object can be obtained either by explicitly creating it with the hg package, or using the <i><b>handle</b></i> function on the numeric handle obtained from normal hg object creation. Using figure as an example, you can either use figh = hg.figure or fig = <i><b>figure</b></i> followed by figh = <i><b>handle</b></i>(fig):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; pkg = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'hg'</span><span style="color: #080;">&#41;</span>
pkg =
        schema.<span style="">package</span>
&nbsp;
&gt;&gt; pkg.<span style="color: #0000FF;">get</span>
               Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'hg'</span>
    DefaultDatabase<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 handle.<span style="">Database</span><span style="color: #080;">&#93;</span>
            Classes<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>30x1 schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#93;</span>
          Functions<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>0x1 handle<span style="color: #080;">&#93;</span>
        JavaPackage<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'com.mathworks.hg'</span>
         Documented<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">for</span> index = <span style="color: #33f;">1</span><span style="color: #F0F;">:</span>numel<span style="color: #080;">&#40;</span>names<span style="color: #080;">&#41;</span>, names<span style="color: #080;">&#123;</span>index<span style="color: #080;">&#125;</span> = pkg.<span style="">Classes</span><span style="color: #080;">&#40;</span>index<span style="color: #080;">&#41;</span>.<span style="">Name</span>; <span style="color: #0000FF;">end</span>
&gt;&gt; names
names =
    <span style="color:#A020F0;">'GObject'</span>
    <span style="color:#A020F0;">'root'</span>
    <span style="color:#A020F0;">'LegendEntry'</span>
    <span style="color:#A020F0;">'Annotation'</span>
    <span style="color:#A020F0;">'figure'</span>
    <span style="color:#A020F0;">'uimenu'</span>
    <span style="color:#A020F0;">'uicontextmenu'</span>
    <span style="color:#A020F0;">'uicontrol'</span>
    <span style="color:#A020F0;">'uitable'</span>
    <span style="color:#A020F0;">'uicontainer'</span>
    <span style="color:#A020F0;">'hgjavacomponent'</span>
    <span style="color:#A020F0;">'uipanel'</span>
    <span style="color:#A020F0;">'uiflowcontainer'</span>
    <span style="color:#A020F0;">'uigridcontainer'</span>
    <span style="color:#A020F0;">'uitoolbar'</span>
    <span style="color:#A020F0;">'uipushtool'</span>
    <span style="color:#A020F0;">'uisplittool'</span>
    <span style="color:#A020F0;">'uitogglesplittool'</span>
    <span style="color:#A020F0;">'uitoggletool'</span>
    <span style="color:#A020F0;">'axes'</span>
    <span style="color:#A020F0;">'hggroup'</span>
    <span style="color:#A020F0;">'text'</span>
    <span style="color:#A020F0;">'line'</span>
    <span style="color:#A020F0;">'patch'</span>
    <span style="color:#A020F0;">'surface'</span>
    <span style="color:#A020F0;">'rectangle'</span>
    <span style="color:#A020F0;">'light'</span>
    <span style="color:#A020F0;">'image'</span>
    <span style="color:#A020F0;">'hgtransform'</span>
    <span style="color:#A020F0;">'uimcosadapter'</span></pre></div></div><p>So far we have just explored the very basic concepts of UDD. You may well be wondering what the big fuss is about, since the information presented so far does not have any immediately-apparent benefits.</p><p>The following set of articles will describe more advanced topics in UDD usage and customizations, using the building blocks presented today. Hopefully you will quickly understand how using UDD can help achieve some very interesting stuff with Matlab.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/' rel='bookmark' title='Creating a simple UDD class'>Creating a simple UDD class</a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-events-and-listeners/' rel='bookmark' title='UDD Events and Listeners'>UDD Events and Listeners</a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/hierarchical-systems-with-udd/' rel='bookmark' title='Hierarchical Systems with UDD'>Hierarchical Systems with UDD</a> <small>UDD objects can be grouped in structured hierarchies - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/new-information-on-hg2/' rel='bookmark' title='New information on HG2'>New information on HG2</a> <small>More information on Matlab's new HG2 object-oriented handle-graphics system...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/introduction-to-udd/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>The javacomponent function</title><link>http://undocumentedmatlab.com/blog/javacomponent/</link> <comments>http://undocumentedmatlab.com/blog/javacomponent/#comments</comments> <pubDate>Wed, 04 Aug 2010 18:00:59 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[GUI]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Semi-documented function]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[UI controls]]></category> <category><![CDATA[schema.prop]]></category> <category><![CDATA[uicontrol]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=1793</guid> <description><![CDATA[Matlab's built-in javacomponent function can be used to display Java components in Matlab application - this article details its usages and limitations<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/common-javacomponent-problems/' rel='bookmark' title='Common javacomponent problems'>Common javacomponent problems</a> <small>The javacomponent function is very useful for placing Java components on-screen, but has a few quirks. ...</small></li><li><a
href='http://undocumentedmatlab.com/blog/javacomponent-background-color/' rel='bookmark' title='Javacomponent background color'>Javacomponent background color</a> <small>This article explains how to align Java component background color with a Matlab color....</small></li><li><a
href='http://undocumentedmatlab.com/blog/hgfeval/' rel='bookmark' title='The hgfeval function'>The hgfeval function</a> <small>The semi-documented hgfeval function can be useful for callback chaining - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function/' rel='bookmark' title='ismembc &#8211; undocumented helper function'>ismembc &#8211; undocumented helper function</a> <small>Matlab has several undocumented internal helper functions that can be useful on their own in some cases. This post presents the ismembc function....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>In this blog I have often showed how using Java components can significantly improve Matlab GUI. Here is a simple reminder:</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><a
target="_blank" href="http://UndocumentedMatlab.com/images/uicomponent.png"><img
alt="sample Java components integrated in Matlab figure window (click for details)" src="http://UndocumentedMatlab.com/images/uicomponent.png" title="sample Java components integrated in Matlab figure window (click for details)" width="450" height="354" /></a><p
class="wp-caption-text">sample Java components integrated in Matlab figure window (click for details)</p></div></center></p><p>Matlab is highly integrated with Java, and Java classes can seamlessly be accessed from Matlab. However, displaying Java GUI objects, as opposed to using computational (non-displayable) Java classes, requires using Matlab&#8217;s built-in <i><b>javacomponent</b></i> function. I have often used this function in past articles here, and today I would like to describe it in more detail.</p><h3 id="javacomponent">javacomponent</h3><p><i><b>javacomponent</b></i>, available since R14 (Matlab 7.0), is yet another <a
target="_blank" href="http://UndocumentedMatlab.com/blog/legend-semi-documented-feature/#Semi-documented">semi-documented</a> built-in function. This means that the function is explained in a comment within the function (which can be seen via the <i><b>edit</b>(&#8216;javacomponent&#8217;)</i> command), but nonetheless does not have official help or doc pages. It is an unsupported function originally intended only for internal Matlab use (which of course doesn&#8217;t mean we can&#8217;t use it).</p><p><i><b>javacomponent</b></i> accepts a component class name (a string) or a reference to a previously-created component object, an optional pixel position parameter (default=[20,20,60,20], just like <i><b>uicontrol</b></i>; may also contain the strings &#8216;North&#8217;, &#8216;South&#8217;, &#8216;East&#8217; or &#8216;West&#8217;), and an optional parent container handle  (defaults to the current figure). <i><b>javacomponent</b></i> then adds the requested component as a child of the requested parent container and wraps it in a Matlab Handle-Graphics (HG) container. <i><b>javacomponent</b></i> returns two handles: the Matlab HG container handle and a reference (handle) to the Java component. Here are some sample invocation formats:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #080;">&#91;</span>jButton, hButton<span style="color: #080;">&#93;</span> = javacomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'javax.swing.JButton'</span><span style="color: #080;">&#41;</span>
hButton =
	javahandle_withcallbacks.<span style="">javax</span>.<span style="">swing</span>.<span style="">JButton</span>
jButton =
          <span style="color: #33f;">158.002197265625</span>
&nbsp;
&gt;&gt; javacomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'javax.swing.JButton'</span>,<span style="color:#A020F0;">'North'</span><span style="color: #080;">&#41;</span>;
&gt;&gt; javacomponent<span style="color: #080;">&#40;</span>javax.<span style="">swing</span>.<span style="">JButton</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Click me!'</span><span style="color: #080;">&#41;</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">50</span>,<span style="color: #33f;">40</span>,<span style="color: #33f;">80</span>,<span style="color: #33f;">30</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
&gt;&gt; javacomponent<span style="color: #080;">&#40;</span>javax.<span style="">swing</span>.<span style="">JButton</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Click me!'</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'East'</span>,hFig<span style="color: #080;">&#41;</span>;</pre></div></div><p>Note the difference between Java object creation and <i><b>javacomponent</b></i>: A pre-created Java object only resides in JVM (Java Virtual Machine) memory, not onscreen, until <i><b>javacomponent</b></i> is called to display it. <i><b>javacomponent</b></i> only creates objects when a class name (string) parameter is passed to it, as a convenience service to programmers. In practice, it is better to separate these two actions: create the Java object separately, and then pass the object&#8217;s reference handle to <i><b>javacomponent</b></i> for display. This enables easier error-trapping if the Java object cannot be created or fails to initialize, before attempting to display the object:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Create and initialize a JScrollBar object</span>
<span style="color: #0000FF;">try</span>
   jScrollbar = javaObjectEDT<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'javax.swing.JScrollBar'</span><span style="color: #080;">&#41;</span>;
   jScrollbar.<span style="">setOrientation</span><span style="color: #080;">&#40;</span>jScrollbar.<span style="">HORIZONTAL</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">catch</span>
   <span style="color: #0000FF;">error</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Cannot create Java-based scroll-bar!'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
<span style="color: #228B22;">% Display the object onscreen</span>
<span style="color: #0000FF;">try</span>
   javacomponent<span style="color: #080;">&#40;</span>jScrollbar,<span style="color:#A020F0;">'South'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">catch</span>
   <span style="color: #0000FF;">error</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Cannot display Java-base scroll-bar!'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>Note that Java GUI object should always use the EDT (Event Dispatch Thread). The reasons for this were outlined in the recent <a
target="_blank" href="http://UndocumentedMatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/">Matlab-EDT article</a>. For this reason, the JScrollBar is created using the built-in <i><b>javaObjectEDT</b></i> function, which exists since R2008a and became documented/supported in R2009a.</p><p><i><b>javacomponent</b></i> accepts parent handles that are figures, toolbars, <i><b>uipanel</b></i>s or <a
target="_blank" href="http://UndocumentedMatlab.com/blog/matlab-layout-managers-uicontainer-and-relatives/"><i><b>uicontainer</b></i>s</a>.  Unfortunately, frames are not <i><b>uicontainer</b></i>s and therefore cannot be used as <i><b>javacomponent</b></i> parents. <b><u>Addendum Aug 6 2010</u></b>: I made an incorrect statement in the original post here regarding <i><b>uipanel</b></i>s, which has now been removed. I thank the reader who pointed this out to me.</p><p>Once the component has been created, even before it has been placed onscreen, it can be manipulated just like any other Java object. For example:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">jButton.<span style="">setText</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Click again!'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% or: set(jButton,'text','…')</span></pre></div></div><p>The component can also be manipulated to some extent via its HG container, which is of a special Matlab type (class) called hgjavacomponent. This includes getting/setting the component position, position units, visibility, resizing callback, tag, <b>UserData</b> etc:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hButton,<span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'norm'</span>, <span style="color:#A020F0;">'position'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">0.2</span>,<span style="color: #33f;">0.3</span>,<span style="color: #33f;">0.1</span>,<span style="color: #33f;">0.05</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hButton,<span style="color:#A020F0;">'visible'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">%note: on/off, not true/false as in Java</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hButton,<span style="color:#A020F0;">'ResizeFcn'</span>,<span style="color: #080;">&#123;</span>@resizeCallbackFunc,param1,param2<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>When adding Java components which are container classes (descendants of <a
target="_blank" rel="nofollow" href="http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Container.html">java.awt.Container</a>), it is important to remember that only other Java components can be added to these containers. Matlab objects such as axes (for plots or images) and <i><b>uicontrol</b></i>s cannot be added since they do not have a Container wrapper.  Therefore, feel free to use these Java containers as long as their contained GUI is limited to Java components (JButton, JComboBox etc.). This limitation is very annoying – it would be very useful to be able to place Matlab axes or <i><b>uicontrol</b></i>s within a JTabbedPane or JSplitPane. Instead, we need to rely on Matlab-based workarounds (<a
target="_blank" href="http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/"><i><b>uitab</b></i></a> and <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/23073-uisplitpane"><i><b>uisplitpane</b></i></a>) which are cumbersome compared to their Java counterparts.</p><p><i><b>javacomponent</b></i> can be used to place not only Swing components but also Swing-extended components onscreen. Matlab itself almost never uses Swing components as-is, instead preferring to use MathWorks-derived extensions of these components, generally in the com.mathworks.mwswing or com.mathworks.widgets packages. These packages and their classes are all in the static Java classpath and are therefore automatically available for use by Matlab programmers.</p><p>Just like Matlab components, <i><b>javacomponent</b></i> can also display third-party or your own Swing-derived components. There are quite a few online sources  for Swing components that can easily be incorporated in your Matlab application. Simply download the relevant class files, add them to your static (via classpath.txt) or dynamic (via <i><b>javaaddpath</b></i>) Java classpath, use <i><b>javacomponent</b></i> to display them, then use their reference handle to manipulate their appearance and behavior.</p><p><i><b>javacomponent</b></i>, useful as it is, has several limitations. In its string variant (classname) it requires a fully-qualified classname that is not inferred automatically. It also has a different parameters format than <i><b>uicontrol</b></i>, which may confuse users. <i><b>javacomponent</b></i> also cannot display <a
target="_blank" rel="nofollow" href="http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Window.html">java.awt.Window</a> components. Finally, it returns two handles – one is a <i><b>handle</b>()</i> reference of the Java object; the second an HG handle (a double numeric value) of the automatically-created HG container – <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/172873">users are often confused</a> as to which property should be set on which of these handles.</p><h3 id="utility">javacomponent-based utility functions</h3><p>To overcome these limitations, I created <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14583-UIComponent"><i><b>UIComponent</b></i></a> – a utility that merges <i><b>uicontrol</b></i> and <i><b>javacomponent</b></i>, available for download on the File Exchange.  It accepts all <i><b>uicontrol</b></i> parameters and styles, as well as any other displayable Java (Swing/AWT) class. <i><b>uicontrol</b></i>&#8216;s calling syntax was preserved for full backwards compatibility. <i><b>uicomponent</b></i> uses the built-in <i><b>uicontrol</b></i> whenever possible (for standard Matlab styles), and <i><b>javacomponent</b></i> for all other Java classes.</p><p><i><b>uicomponent</b></i> returns the same two handles that <i><b>javacomponent</b></i> returns (namely, a Java reference handle and a numeric HG handle), modified to include each other&#8217;s properties and handles (yet another undocumented trick that merits a dedicated article). Here are some examples (more can be found in <i><b>uicomponent</b></i>&#8216;s help comment):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">uicomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'edit'</span>, <span style="color:#A020F0;">'String'</span>,<span style="color:#A020F0;">'hello'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% a regular uicontrol</span>
uicomponent<span style="color: #080;">&#40;</span>hFig, <span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'edit'</span>, <span style="color:#A020F0;">'String'</span>,<span style="color:#A020F0;">'hello'</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% specify parent</span>
uicomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'jspinner'</span>,<span style="color:#A020F0;">'value'</span>,<span style="color: #33f;">7</span><span style="color: #080;">&#41;</span>;
uicomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'javax.swing.jslider'</span>,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'myObj'</span><span style="color: #080;">&#41;</span>; 
uicomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'JComboBox'</span>,<span style="color: #080;">&#123;</span><span style="color: #33f;">1</span>,<span style="color: #0000FF;">pi</span>,<span style="color:#A020F0;">'text'</span><span style="color: #080;">&#125;</span>,<span style="color:#A020F0;">'editable'</span>,<span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>Another File Exchange submission which aims to tackle some of <i><b>javacomponent</b></i>&#8216;s limitations is Malcolm Lidierth&#8217;s <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/15580"><i><b>JCONTROL</b></i></a>. <i><b>jcontrol</b></i> uses Matlab&#8217;s new object-oriented class approach and has the benefit of returning just a single handle object, which aggregates the handles for both HG container and the contained Java object.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/common-javacomponent-problems/' rel='bookmark' title='Common javacomponent problems'>Common javacomponent problems</a> <small>The javacomponent function is very useful for placing Java components on-screen, but has a few quirks. ...</small></li><li><a
href='http://undocumentedmatlab.com/blog/javacomponent-background-color/' rel='bookmark' title='Javacomponent background color'>Javacomponent background color</a> <small>This article explains how to align Java component background color with a Matlab color....</small></li><li><a
href='http://undocumentedmatlab.com/blog/hgfeval/' rel='bookmark' title='The hgfeval function'>The hgfeval function</a> <small>The semi-documented hgfeval function can be useful for callback chaining - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function/' rel='bookmark' title='ismembc &#8211; undocumented helper function'>ismembc &#8211; undocumented helper function</a> <small>Matlab has several undocumented internal helper functions that can be useful on their own in some cases. This post presents the ismembc function....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/javacomponent/feed/</wfw:commentRss> <slash:comments>18</slash:comments> </item> <item><title>New information on HG2</title><link>http://undocumentedmatlab.com/blog/new-information-on-hg2/</link> <comments>http://undocumentedmatlab.com/blog/new-information-on-hg2/#comments</comments> <pubDate>Mon, 10 May 2010 22:09:39 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[HG2]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema.class]]></category> <category><![CDATA[schema.prop]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=1473</guid> <description><![CDATA[More information on Matlab's new HG2 object-oriented handle-graphics system<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/introduction-to-udd/' rel='bookmark' title='Introduction to UDD'>Introduction to UDD</a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-hg2/' rel='bookmark' title='Matlab&#8217;s HG2 mechanism'>Matlab&#8217;s HG2 mechanism</a> <small>HG2 is presumably the next generation of Matlab graphics. This article tries to explore its features....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/' rel='bookmark' title='uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager'>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li><li><a
href='http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/' rel='bookmark' title='Creating a simple UDD class'>Creating a simple UDD class</a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Last week I posted a couple of articles on <a
target="_blank" href="http://undocumentedmatlab.com/blog/undocumented-feature-function/">the undocumented <b><i>feature</i></b> function</a> and Matlab&#8217;s apparent move towards a <a
target="_blank" href="http://undocumentedmatlab.com/blog/matlab-hg2/">class-based Handle-Graphics system</a> called HG2.</p><p>Apparently I caused a bit of a stir&#8230;</p><p>This is normally a weekly blog. But I wanted to share some additional relevant information as well as some interesting tips I received in private communications. Please note that much of the following is speculation or guesswork and may be incorrect or even entirely wacky. Please read the following with more than the usual grain of skepticism&#8230;</p><h3 id="UDD">UDD</h3><p>A bit of historical background: Matlab&#8217;s existing Handle Graphics system is based on UDD (Unified Data Definition?) objects. Prior to Matlab Release 12 (a.k.a. 6.0) back in 2000, Matlab was written exclusively in C and HG and Simulink used differing approaches to objects in the MathWorks codebase. UDD was then added for R12 using C++ code with C wrappers for internal use by the MathWorks developers. UDD enabled a new unified approach for HG and Simulink (recall the major overhaul to the Matlab interface in that release, which also modified the GUI to be Java-based). While the HG handles remained numeric, behind the scenes they relied on the new UDD system, which remained undocumented.</p><p>Matlab users who wished to leverage UDD classes could (and still can) access it via some undocumented interface functions: <i><b>handle, handle.listener, handle.event, classhandle, schema.prop, schema.class, schema.event</b></i> (and other <i><b>schema.*</b></i> functions), <i><b>findprop, findclass, findevent</b></i> and several others. Some of these functions were mentioned in past articles on this blog, and others will perhaps be explained in future articles. You can find numerous mentions and usage examples of UDD in the Matlab codebase that is part of each Matlab installation.</p><p>In /toolbox/matlab/helptools/+helpUtils/@HelpProcess/getHelpText.m we can see a related feature (<i><b>feature</b></i>(&#8216;SearchUUDClassesForHelp&#8217;, flag)) which can apparently be used to allow access to the h1 line and help text for UDD methods. Unfortunately, I have not found any relevant UDD candidates for this. I would be very happy to hear if you know of any objects/methods which have a UDD help section.</p><h3 id="MCOS">MCOS</h3><p>Perhaps Matlab&#8217;s Class Object System (MCOS), <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/97653#247876">first introduced in R14</a> (a.k.a. 7.0, released in 2004) grew out of the UDD beginnings, and perhaps it was developed separately. The fact is that it shared several terms and concepts (&#8220;schema&#8221;, properties meta-data, events) with UDD, although no direct interaction between UDD and MCOS exists, AFAIK.</p><p>As an interesting side-note, MCOS was introduced as an opt-in beta-testing feature in R14SP2 (7.0.4, released in 2005). This beta feature cannot be found in the <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/techdoc/rn/bqsq452.html">official online version of the R14SP2 release notes</a>, but can be found in the hardcover version pages 10-11:<br
/> <q>New syntax and features for creating and working with classes in MATLAB. For R14SP2, these features are at a Beta level. If you are interested in being a Beta tester for these features, see &#8220;Beta Test the MATLAB Class System&#8221; on page 11.</p><p><strong>Beta Test the MATLAB Class System</strong>. MATLAB 7.0.4 includes a Beta version of new syntax and features for working with classes in MATLAB, which simplify and expand object-oriented programming capabilities in MATLAB. Participation in this Beta program is open only to customers who are current<br
/> on their maintenance for MATLAB. Trial passcodes will not be made available for this Beta test. If you are interested in being a Beta tester for these features, register on the MathWorks Web site, at <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/products/beta/r14sp2/signup_newfeatures.html">http://www.mathworks.com/products/beta/r14sp2/signup_newfeatures.html</a>.</q> (needless to say, this webpage was since removed&#8230;)</p><p>The MCOS syntax has changed between releases and was not very stable, until it was formally introduced in R2008a (a.k.a. 7.6, released in 2008). You can look at /toolbox/matlab/iofun/@memmapfile/memmapfile.m to see the MCOS evolution from R14 onward.</p><h3 id="HG2">HG2</h3><p>The new HG2 appears to be a merger of MCOS and UDD, using MCOS infrastructure for UDD classes and properties, finally throwing away the old numeric handles and C wrappers for the more powerful object-oriented approach.</p><p>For the transition period between HG and HG2, there seems to be a dedicated feature: <i><b>feature</b></i>(&#8216;HGtoCOS&#8217;, handle) apparently converts a UDD (&#8220;HG&#8221;) handle into an HG2 (&#8220;COS&#8221;) handle. You can also use <i><b>feature</b></i>(&#8216;HGtoCOS&#8217;, 0) to obtain an MCOS object of the desktop (=handle 0). Here is a sample result on a Matlab 2009 release:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; hFig = <span style="color: #0000FF;">figure</span>
hFig =
     <span style="color: #33f;">1</span>
&nbsp;
&gt;&gt; fmcos = feature<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'HGtoCOS'</span>, hFig<span style="color: #080;">&#41;</span>
fmcos =
&nbsp;
  gbtmcos.<span style="color: #0000FF;">figure</span> handle
&nbsp;
  Package<span style="color: #F0F;">:</span> gbtmcos
&nbsp;
  Properties<span style="color: #F0F;">:</span>
                 Alphamap<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x64 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
             BeingDeleted<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
               BusyAction<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'queue'</span>
            ButtonDownFcn<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
                 Children<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>0x1 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
                 Clipping<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
          CloseRequestFcn<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'closereq'</span>
                    Color<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">0.8000</span> <span style="color: #33f;">0.8000</span> <span style="color: #33f;">0.8000</span><span style="color: #080;">&#93;</span>
                 <span style="color: #0000FF;">Colormap</span><span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>64x3 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
                      <span style="color: #F0F;">...</span>  <span style="color: #080;">&#40;</span><span style="color: #0000FF;">all</span> the regular <span style="color: #0000FF;">figure</span> properties<span style="color: #080;">&#41;</span></pre></div></div><p>Note that in that here, the new object package was called GBTMCOS &#8211; perhaps meaning a GBT version of the MCOS system. This corresponds to the <i><b>feature</b></i>(&#8216;useGBT2&#8242;) that I reported in the <a
target="_blank" href="http://undocumentedmatlab.com/blog/undocumented-feature-function/">features article</a>. I have absolutely no idea what GBT stands for, whether it is a synonym for HG2 or not exactly, and what the differences are between GBT1.5 and GBT2. In any case, in R2010a, the same <i><b>feature</b></i>(&#8216;HGtoCOS&#8217;, handle) code returns a ui.figure object: &#8220;GBTMCOS&#8221; was simply renamed &#8220;UI&#8221;.</p><p>I do not know how to convert an HG2 back to a UDD/HG handle. None of the following appears to work:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; fmcos.<span style="">getdoubleimpl</span>
<span style="color: #0000FF;">ans</span> =
    -<span style="color: #33f;">1</span>
&nbsp;
&gt;&gt; fmcos.<span style="color: #0000FF;">double</span>
<span style="color: #0000FF;">ans</span> =
on
&nbsp;
&gt;&gt; <span style="color: #0000FF;">double</span><span style="color: #080;">&#40;</span>fmcos<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
    -<span style="color: #33f;">1</span>
&nbsp;
&gt;&gt; handle<span style="color: #080;">&#40;</span>fmcos<span style="color: #080;">&#41;</span>
??? <span style="color: #0000FF;">Error</span> using ==&gt; handle
Cannot convert to handle.</pre></div></div><p>I would love to hear any additional information on these subjects, either anonymously or on record. You can use either a direct mail (see link at the top-right of this page) or the <a
href="#respond">comments section</a>.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/introduction-to-udd/' rel='bookmark' title='Introduction to UDD'>Introduction to UDD</a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-hg2/' rel='bookmark' title='Matlab&#8217;s HG2 mechanism'>Matlab&#8217;s HG2 mechanism</a> <small>HG2 is presumably the next generation of Matlab graphics. This article tries to explore its features....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/' rel='bookmark' title='uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager'>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li><li><a
href='http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/' rel='bookmark' title='Creating a simple UDD class'>Creating a simple UDD class</a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/new-information-on-hg2/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Continuous slider callback</title><link>http://undocumentedmatlab.com/blog/continuous-slider-callback/</link> <comments>http://undocumentedmatlab.com/blog/continuous-slider-callback/#comments</comments> <pubDate>Mon, 08 Feb 2010 09:13:39 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[GUI]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Listeners]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[UI controls]]></category> <category><![CDATA[Callbacks]]></category> <category><![CDATA[FindJObj]]></category> <category><![CDATA[Listener]]></category> <category><![CDATA[schema.prop]]></category> <category><![CDATA[uicontrol]]></category> <category><![CDATA[Undocumented feature]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=1052</guid> <description><![CDATA[Matlab slider uicontrols do not enable a continuous-motion callback by default. This article explains how this can be achieved using undocumented features.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/controlling-callback-re-entrancy/' rel='bookmark' title='Controlling callback re-entrancy'>Controlling callback re-entrancy</a> <small>Callback reentrancy is a major problem for frequently-fired events. Luckily, it can easily be solved....</small></li><li><a
href='http://undocumentedmatlab.com/blog/inactive-control-tooltips-event-chaining/' rel='bookmark' title='Inactive Control Tooltips &amp; Event Chaining'>Inactive Control Tooltips &#038; Event Chaining</a> <small>Inactive Matlab uicontrols cannot normally display their tooltips. This article shows how to do this with a combination of undocumented Matlab and Java hacks....</small></li><li><a
href='http://undocumentedmatlab.com/blog/setting-listbox-mouse-actions/' rel='bookmark' title='Setting listbox mouse actions'>Setting listbox mouse actions</a> <small>Matlab listbox uicontrol can be modified to detect mouse events for right-click context menus, dynamic tooltips etc....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uicontrol-callbacks/' rel='bookmark' title='Uicontrol callbacks'>Uicontrol callbacks</a> <small>This post details undocumented callbacks exposed by the underlying Java object of Matlab uicontrols, that can be used to modify the control's behavior in a multitude of different events...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Every few months, a CSSM forum reader asks how to set up a continuously-invoked slider callback: Matlab&#8217;s <a
target="_blank" rel="nofollow" href="http://blinkdagger.com/matlab/matlab-gui-tutorial-slider/">slider uicontrol</a> invokes the user callback only when the mouse button is released, and not continuously while the slider&#8217;s thumb is dragged. This functionality was again referred-to <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/272224">yesterday</a>, and I decided it merits a dedicated post.</p><p>There are three distinct simple ways to achieve continuous callbacks:</p><h3 id="Java_Callbacks">Using Java callbacks</h3><p>As explained in an earlier <a
target="_blank" href="http://undocumentedmatlab.com/blog/uicontrol-callbacks/">article</a>, Matlab uicontrols are basically Java Swing objects that possess a large number of useful callbacks. Matlab sliders&#8217; underlying Java objects, which are really not <a
target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/components/slider.html">JSliders</a> but <a
target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html#operation">JScrollBars</a>, have an <b>AdjustmentValueChangedCallback</b> property that is useful for our purposes and is accessible using the <a
target="_blank" href="http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/"><b><i>FindJObj utility</i></b></a>. Simply download <b><i>FindJObj</i></b> from the <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">File Exchange</a>, and then:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hSlider = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'slider'</span>, <span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span>;
jScrollBar = findjobj<span style="color: #080;">&#40;</span>hSlider<span style="color: #080;">&#41;</span>;
jScrollBar.<span style="">AdjustmentValueChangedCallback</span> = @myCbFcn;
<span style="color: #228B22;">% or: set(jScrollBar,'AdjustmentValueChangedCallback',@myCbFcn)</span></pre></div></div><p>Where <i>myCbFcn</i> is the Matlab callback function that will be invoked continuously when the arrow buttons are depressed or the slider&#8217;s thumb is dragged.</p><h3 id="Event_Listener">Using an event listener</h3><p>An alternative to the Java route is to use Matlab&#8217;s undocumented <b><i>handle.listener</i></b> function to listen to the slider&#8217;s <b>Action</b> event, as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hListener = <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>hSlider,<span style="color:#A020F0;">'ActionEvent'</span>,@myCbFcn<span style="color: #080;">&#41;</span>;</pre></div></div><p>This alternative is used by Matlab&#8217;s own <b><i>imscrollpanel</i></b> function:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">if</span> isJavaFigure
   <span style="color: #228B22;">% Must use these ActionEvents to get continuous events fired as slider</span>
   <span style="color: #228B22;">% thumb is dragged. Regular callbacks on sliders give only one event</span>
   <span style="color: #228B22;">% when the thumb is released.</span>
   hSliderHorListener = <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>hSliderHor,<span style="color: #F0F;">...</span>
      <span style="color:#A020F0;">'ActionEvent'</span>,@scrollHorizontal<span style="color: #080;">&#41;</span>;
   hSliderVerListener = <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>hSliderVer,<span style="color: #F0F;">...</span>
      <span style="color:#A020F0;">'ActionEvent'</span>,@scrollVertical<span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">setappdata</span><span style="color: #080;">&#40;</span>hScrollpanel,<span style="color:#A020F0;">'sliderListeners'</span>,<span style="color: #F0F;">...</span>
      <span style="color: #080;">&#91;</span>hSliderHorListener hSliderVerListener<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">else</span>
   <span style="color: #228B22;">% Unfortunately, the event route is only available with Java Figures,</span>
   <span style="color: #228B22;">% so platforms without Java Figure support get discrete events only</span>
   <span style="color: #228B22;">% when the mouse is released from dragging the slider thumb.</span>
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hSliderHor,<span style="color:#A020F0;">'callback'</span>,@scrollHorizontal<span style="color: #080;">&#41;</span>
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hSliderVer,<span style="color:#A020F0;">'callback'</span>,@scrollVertical<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">end</span></pre></div></div><h3 id="Property_Listener">Using a property listener</h3><p>The <b><i>handle.listener</i></b> function can also be used to listen to property value changes. In our case, set a post-set listener, that gets triggered immediately following <b>Value</b> property updates, as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hhSlider = handle<span style="color: #080;">&#40;</span>hSlider<span style="color: #080;">&#41;</span>;
hProp = <span style="color: #0000FF;">findprop</span><span style="color: #080;">&#40;</span>hhSlider,<span style="color:#A020F0;">'Value'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% a schema.prop object</span>
hListener = <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>hhSlider,hProp,<span style="color:#A020F0;">'PropertyPostSet'</span>,@myCbFcn<span style="color: #080;">&#41;</span>;</pre></div></div><p>In addition to &#8216;PropertyPostSet&#8217;, we could also listen on &#8216;PropertyPreSet&#8217;, which is triggered immediately <u>before</u> the property is modified. There are also corresponding &#8216;*Get&#8217; options. In relatively old Matlab releases (I believe R2007b and earlier, but I&#8217;m not certain), the option names were simply &#8216;PostSet&#8217;, &#8216;PreSet&#8217; etc., without the &#8216;Property&#8217; prefix.</p><p>Do you know of any other way to achieve continuous callbacks? If so, I would be delighted to hear in the comments section below.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/controlling-callback-re-entrancy/' rel='bookmark' title='Controlling callback re-entrancy'>Controlling callback re-entrancy</a> <small>Callback reentrancy is a major problem for frequently-fired events. Luckily, it can easily be solved....</small></li><li><a
href='http://undocumentedmatlab.com/blog/inactive-control-tooltips-event-chaining/' rel='bookmark' title='Inactive Control Tooltips &amp; Event Chaining'>Inactive Control Tooltips &#038; Event Chaining</a> <small>Inactive Matlab uicontrols cannot normally display their tooltips. This article shows how to do this with a combination of undocumented Matlab and Java hacks....</small></li><li><a
href='http://undocumentedmatlab.com/blog/setting-listbox-mouse-actions/' rel='bookmark' title='Setting listbox mouse actions'>Setting listbox mouse actions</a> <small>Matlab listbox uicontrol can be modified to detect mouse events for right-click context menus, dynamic tooltips etc....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uicontrol-callbacks/' rel='bookmark' title='Uicontrol callbacks'>Uicontrol callbacks</a> <small>This post details undocumented callbacks exposed by the underlying Java object of Matlab uicontrols, that can be used to modify the control's behavior in a multitude of different events...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/continuous-slider-callback/feed/</wfw:commentRss> <slash:comments>30</slash:comments> </item> </channel> </rss>

<!-- W3 Total Cache: Minify debug info:
Engine:             disk: basic
Theme:              b7666
Template:           tag
-->
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: undocumentedmatlab.com @ 2012-05-21 20:22:55 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/tag/schemaprop/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      2.748s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1337656973; expires=Wed, 22-May-2013 03:22:53 GMT; path=/
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Tue, 22 May 2012 03:22:55 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Tue, 22 May 2012 04:22:55 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               fffcb5a7cdddb138ae0f71e52e4a0713
Content-Encoding:   gzip
-->
