<?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; Handle graphics</title> <atom:link href="http://undocumentedmatlab.com/blog/tag/handle-graphics/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Thu, 02 Feb 2012 00:24:18 +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>Determining axes zoom state</title><link>http://undocumentedmatlab.com/blog/determining-axes-zoom-state/</link> <comments>http://undocumentedmatlab.com/blog/determining-axes-zoom-state/#comments</comments> <pubDate>Thu, 10 Nov 2011 18:45:38 +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[Pure Matlab]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2529</guid> <description><![CDATA[The information of whether or not an axes is zoomed or panned can easily be inferred from an internal undocumented object.<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/tri-state-checkbox/' rel='bookmark' title='Tri-state checkbox'>Tri-state checkbox</a> <small>Matlab checkboxes can easily be made to support tri-state functionality....</small></li><li><a
href='http://undocumentedmatlab.com/blog/recovering-previous-editor-state/' rel='bookmark' title='Recovering previous editor state'>Recovering previous editor state</a> <small>Recovering the previous state of the Matlab editor and its loaded documents is possible using a built-in backup config file. ...</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></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>A couple of days ago, a reader of Matlab&#8217;s official Desktop blog <a
target="_blank" rel="nofollow" href="http://blogs.mathworks.com/desktop/2007/12/10/focused-on-zooming/#comment-8204">asked</a> whether it is possible to determine if an axes has been zoomed or not.</p><p>I have encountered this question myself some time ago, when I tried to customize a radar plot: The grid in radar plots does not automatically re-draw when the plot is zoomed, as in regular rectangular plots. Instead, the radial (angle) and circular (range) grid lines are statically painted when the plot is created, and remain fixed when the plot is zoomed or panned. Therefore, if we zoom in on a small-enough plot segment, we will not see any grid lines at all. It would be beneficial to repaint the grid-lines upon every zoom and pan event. I will not dive into the details today, but the important thing for today&#8217;s article is that the algorithm needed to know whether or not the axes is currently zoomed or not.</p><p>The official response is that this information is not readily available. We could of course store the axes limits somewhere and then compare them to the current limits in run-time. This will cause complications if the plotted data (and thereby the axes limits) change automatically during program use, even without any zooming/panning. It is also problematic if the user resets the zoom limits (as Jiro has correctly <a
target="_blank" rel="nofollow" href="http://blogs.mathworks.com/desktop/2007/12/10/focused-on-zooming/#comment-8206">pointed out</a>).</p><p>Today I&#8217;ll highlight another possible solution, that perhaps not many Matlab users are familiar with: Apparently, whenever zooming or panning occur, a hidden <b>ApplicationData</b> object is automatically added to the affected axes, with information about the original axes meta-data: limits, aspect ratio, camera info and view angles. This object is also automatically updated whenever we use <b><i>zoom reset</i></b> to reset the zoom limits.</p><p>So basically, all we have to do in run-time is to compare our current access limits with the stored info: if they are the same (or if the app-data object is missing) then the plot is unzoomed and unpanned; otherwise it is. So simple.</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">origInfo = <span style="color: #0000FF;">getappdata</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>, <span style="color:#A020F0;">'matlab_graphics_resetplotview'</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>origInfo<span style="color: #080;">&#41;</span>
   isZoomed = <span style="color: #0000FF;">false</span>;
<span style="color: #0000FF;">elseif</span> isequal<span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'XLim'</span><span style="color: #080;">&#41;</span>, origInfo.<span style="color: #0000FF;">XLim</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">&amp;&amp;</span> <span style="color: #F0F;">...</span>
       <span style="">isequal</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'YLim'</span><span style="color: #080;">&#41;</span>, origInfo.<span style="color: #0000FF;">YLim</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">&amp;&amp;</span> <span style="color: #F0F;">...</span>
       <span style="">isequal</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'ZLim'</span><span style="color: #080;">&#41;</span>, origInfo.<span style="color: #0000FF;">ZLim</span><span style="color: #080;">&#41;</span>
   isZoomed = <span style="color: #0000FF;">false</span>;
<span style="color: #0000FF;">else</span>
   isZoomed = <span style="color: #0000FF;">true</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>This still does not solve the problem of limit changes when the plot data is changed, but it may perhaps be a bit easier to use than manually storing the limits before plotting. (And yes, of course the if-else statement above could be made a one-liner logical construct, but I think this way is more readable).</p><p>Zooming and panning add some additional data to <b>ApplicationData</b>, and also use/modify some other hidden properties of the axes handle (use the <a
target="_blank" href="http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/"><b><i>getundoc</i></b> function</a> to see them). If you use one of them for any useful purpose, please report your usage in a <a
href="http://undocumentedmatlab.com/blog/determining-axes-zoom-state/#Respond">comment below</a>.</p><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/tri-state-checkbox/' rel='bookmark' title='Tri-state checkbox'>Tri-state checkbox</a> <small>Matlab checkboxes can easily be made to support tri-state functionality....</small></li><li><a
href='http://undocumentedmatlab.com/blog/recovering-previous-editor-state/' rel='bookmark' title='Recovering previous editor state'>Recovering previous editor state</a> <small>Recovering the previous state of the Matlab editor and its loaded documents is possible using a built-in backup config file. ...</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></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/determining-axes-zoom-state/feed/</wfw:commentRss> <slash:comments>2</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>Controlling plot data-tips</title><link>http://undocumentedmatlab.com/blog/controlling-plot-data-tips/</link> <comments>http://undocumentedmatlab.com/blog/controlling-plot-data-tips/#comments</comments> <pubDate>Wed, 14 Sep 2011 20:42:40 +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[Undocumented function]]></category> <category><![CDATA[modemanager]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[Undocumented property]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2432</guid> <description><![CDATA[Data-tips are an extremely useful plotting tool that can easily be controlled programmatically.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/accessing-plot-brushed-data/' rel='bookmark' title='Accessing plot brushed data'>Accessing plot brushed data</a> <small>Plot data brushing can be accessed programmatically using very simple pure-Matlab code...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-linesmoothing-property/' rel='bookmark' title='Plot LineSmoothing property'>Plot LineSmoothing property</a> <small>LineSmoothing is a hidden and undocumented plot line property that creates anti-aliased (smooth unpixelized) lines in Matlab plots...</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/com-activex-tips/' rel='bookmark' title='COM/ActiveX tips &amp; tricks'>COM/ActiveX tips &#038; tricks</a> <small>This article describes several little-known tips useful for COM / ActiveX programming in Matlab...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Plot <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/creating_plots/f4-44221.html">data tips</a> are a great visualization aid for Matlab plots. They enable users to interactively click on a plot location and see a tool-tip that contains the clicked location&#8217;s coordinates. The displayed tooltip text is even customizable using documented properties of the <i><b><a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/ref/datacursormode.html">datacursormode</a></b></i> object.</p><p><center><div
class="wp-caption aligncenter" style="width: 441px"><img
alt="plot data tips" src="http://UndocumentedMatlab.com/images/datatips.png" title="plot data tips" width="431" /><p
class="wp-caption-text">plot data tips</p></div></center></p><p>A client has recently asked me to automatically display an attached data-tip to the last data point of a plotted time series of values. The idea was to immediately see what the latest value of the data series is.</p><p>Unfortunately, the official documentation clearly says that:</p><blockquote><p>You place data tips only by clicking data objects on graphs. You cannot place them programmatically (by executing code to position a data cursor).</p></blockquote><p>Well, this has never stopped us before, has it?</p><h3 id="Creating">Creating new data tips</h3><p>Under the hood, data tips use a data-cursor mode, which shares many similarities in behavior and programming code with the other plot modes (zoom, pan, <a
target="_blank" href="http://undocumentedmatlab.com/blog/accessing-plot-brushed-data/">data-brushing</a>, etc.). At any one time, only a single such mode can be active in any figure window (this is a known limitation of the design). The code itself it actually quite complex and handles numerous edge-cases. Understanding it by simply reading the code (under %matlabroot%\toolbox\matlab\graphics\) is actually pretty difficult. A much easier way to understand the programming flow is to liberally distribute breakpoints (start in <i>datacursormode.m</i>) and interactively activate the functionality, then debug the code step-by-step.</p><p>Luckily, it turns out that the code to create a new data-tip is actually quite simple: first get the data-cursor mode object, then create a new data tip using the mode&#8217;s <i>createDatatip()</i> method, update some data-tip properties and finally update the data-tip&#8217;s position:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% First plot the data</span>
hLine = <span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>xdata, ydata<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% First get the figure's data-cursor mode, activate it, and set some of its properties</span>
cursorMode = datacursormode<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>cursorMode, <span style="color:#A020F0;">'enable'</span>,<span style="color:#A020F0;">'on'</span>, <span style="color:#A020F0;">'UpdateFcn'</span>,@setDataTipTxt, <span style="color:#A020F0;">'NewDataCursorOnClick'</span>,<span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">% Note: the optional @setDataTipTxt is used to customize the data-tip's appearance</span>
&nbsp;
<span style="color: #228B22;">% Note: the following code was adapted from %matlabroot%\toolbox\matlab\graphics\datacursormode.m</span>
<span style="color: #228B22;">% Create a new data tip</span>
hTarget = handle<span style="color: #080;">&#40;</span>hLine<span style="color: #080;">&#41;</span>;
hDatatip = cursorMode.<span style="">createDatatip</span><span style="color: #080;">&#40;</span>hTarget<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Create a copy of the context menu for the datatip:</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip,<span style="color:#A020F0;">'UIContextMenu'</span>,<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>cursorMode,<span style="color:#A020F0;">'UIContextMenu'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip,<span style="color:#A020F0;">'HandleVisibility'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip,<span style="color:#A020F0;">'Host'</span>,hTarget<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip,<span style="color:#A020F0;">'ViewStyle'</span>,<span style="color:#A020F0;">'datatip'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Set the data-tip orientation to top-right rather than auto</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip,<span style="color:#A020F0;">'OrientationMode'</span>,<span style="color:#A020F0;">'manual'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip,<span style="color:#A020F0;">'Orientation'</span>,<span style="color:#A020F0;">'top-right'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Update the datatip marker appearance</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip, <span style="color:#A020F0;">'MarkerSize'</span>,<span style="color: #33f;">5</span>, <span style="color:#A020F0;">'MarkerFaceColor'</span>,<span style="color:#A020F0;">'none'</span>, <span style="color: #F0F;">...</span>
              <span style="color:#A020F0;">'MarkerEdgeColor'</span>,<span style="color:#A020F0;">'k'</span>, <span style="color:#A020F0;">'Marker'</span>,<span style="color:#A020F0;">'o'</span>, <span style="color:#A020F0;">'HitTest'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Move the datatip to the right-most data vertex point</span>
position = <span style="color: #080;">&#91;</span>xdata<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#41;</span>,ydata<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#41;</span>,<span style="color: #33f;">1</span>; xdata<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#41;</span>,ydata<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#41;</span>,-<span style="color: #33f;">1</span><span style="color: #080;">&#93;</span>;
update<span style="color: #080;">&#40;</span>hDatatip, position<span style="color: #080;">&#41;</span>;</pre></div></div><h3 id="Updating">Updating an existing data tip</h3><p>To modify the appearance of a data-tip, we first need to get access to the <code>hDatatip</code> object that we created earlier, either programmatically, or interactively (or both). Since we can access pre-stored handles only of programmatically-created (not interactively-created) data-tips, we need to use a different method. There are actually two ways to do this:</p><p>The basic way is to search the relevant axes for objects that have <b>Tag</b>=&#8217;DataTipMarker&#8217;. For each data-tip, we will get two such handles: one for the marker (<b>Type</b>=&#8217;line&#8217;) and the other for the text box tooltip (<b>Type</b>=&#8217;text&#8217;). We can use these to update (for example) the marker size, color and style; and the text&#8217;s font, border and colors.</p><p>A better way is to access the <code>graphics.datatip</code> object itself. This can be done using two hidden properties of the <i><b>datacursormode</b></i> object:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Get the list of all data-tips in the current figure</span>
&gt;&gt; cursorMode = datacursormode<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>
cursorMode =
	graphics.<span style="">datacursormanager</span>
&nbsp;
&gt;&gt; cursorMode.<span style="">DataCursors</span>
<span style="color: #0000FF;">ans</span> =
	graphics.<span style="">datatip</span><span style="color: #F0F;">:</span> <span style="color: #33f;">2</span>-by-<span style="color: #33f;">1</span>
&nbsp;
&gt;&gt; cursorMode.<span style="">CurrentDataCursor</span>
<span style="color: #0000FF;">ans</span> =
	graphics.<span style="">datatip</span>
&nbsp;
&gt;&gt; cursorMode.<span style="">CurrentDataCursor</span>.<span style="color: #0000FF;">get</span>
            Annotation<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 hg.<span style="">Annotation</span><span style="color: #080;">&#93;</span>
           DisplayName<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
           HitTestArea<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
          BeingDeleted<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</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>2x1 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
              Clipping<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
             CreateFcn<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
             DeleteFcn<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
            BusyAction<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'queue'</span>
      HandleVisibility<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
               HitTest<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
         Interruptible<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                Parent<span style="color: #F0F;">:</span> <span style="color: #33f;">492.005493164063</span>
    SelectionHighlight<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                   Tag<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
                  <span style="color: #0000FF;">Type</span><span style="color: #F0F;">:</span> <span style="color:#A020F0;">'hggroup'</span>
              UserData<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
              Selected<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
             FontAngle<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'normal'</span>
              FontName<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'Helvetica'</span>
              FontSize<span style="color: #F0F;">:</span> <span style="color: #33f;">8</span>
             FontUnits<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'points'</span>
            FontWeight<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'normal'</span>
             EdgeColor<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">0.8</span> <span style="color: #33f;">0.8</span> <span style="color: #33f;">0.8</span><span style="color: #080;">&#93;</span>
       BackgroundColor<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">1</span> <span style="color: #33f;">0.933333333333333</span><span style="color: #080;">&#93;</span>
             TextColor<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: #080;">&#93;</span>
                Marker<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'o'</span>
            MarkerSize<span style="color: #F0F;">:</span> <span style="color: #33f;">5</span>
       MarkerEdgeColor<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'k'</span>
       MarkerFaceColor<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'none'</span>
       MarkerEraseMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'normal'</span>
             Draggable<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                String<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'Date: 01/09/11'</span>  <span style="color:#A020F0;">'Value: 573.24'</span><span style="color: #080;">&#125;</span>
               Visible<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
             StringFcn<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
             UpdateFcn<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
         <span style="color: #0000FF;">UIContextMenu</span><span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">uicontextmenu</span><span style="color: #080;">&#93;</span>
                  Host<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 graph2d.<span style="">lineseries</span><span style="color: #080;">&#93;</span>
           Interpolate<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span></pre></div></div><p>We can see that the returned <code>graphics.datatip</code> object includes properties of both the text-box and the marker, making it easy to modify. Moreover, we can use its aforementioned <i>update</i> method to move the datatip to a different plot position (see example in the code above). In addition, we can also use the self-explanatory <i>getCursorInfo(), getaxes(), makeCurrent(), movetofront()</i> methods, and a few others.</p><h3 id="Properties">Cursor mode and data-tip properties</h3><p>The <code>graphics.datacursormanager</code> and the <code>graphics.datatip</code> objects have several public properties that we can use:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; cursorMode.<span style="color: #0000FF;">get</span>
              Enable<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
    SnapToDataVertex<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
        DisplayStyle<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'datatip'</span>
           UpdateFcn<span style="color: #F0F;">:</span> @setDataTipTxt
              <span style="color: #0000FF;">Figure</span><span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">figure</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; cursorMode.<span style="">CurrentDataCursor</span>.<span style="color: #0000FF;">get</span>
            Annotation<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 hg.<span style="">Annotation</span><span style="color: #080;">&#93;</span>
           DisplayName<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
           HitTestArea<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
      <span style="color: #F0F;">...</span> <span style="color: #228B22;">% See the list above</span></pre></div></div><p>Both these objects have plenty of additional hidden properties. You can inspect them using my <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object">uiinspect utility</a>. Here is a brief list for reference (R2011b):</p><p><code>graphics.datacursormanager</code>:</p><ul><li>CurrentDataCursor</li><li>DataCursors</li><li>Debug</li><li>DefaultExportVarName</li><li>DefaultPanelPosition</li><li>EnableAxesStacking</li><li>EnableZStacking</li><li>ExternalListeners</li><li>HiddenUpdateFcn</li><li>NewDataCursorOnClick</li><li>OriginalRenderer</li><li>OriginalRendererMode</li><li>PanelDatatipHandle</li><li>PanelHandle</li><li>PanelTextHandle</li><li>UIContextMenu</li><li>UIState</li><li>ZStackMinimum</li></ul><p><code>graphics.datatip</code>:</p><ul><li>ALimInclude</li><li>ApplicationData</li><li>Behavior</li><li>CLimInclude</li><li>DataCursorHandle</li><li>DataManagerHandle</li><li>Debug</li><li>DoThrowStartDragEvent</li><li>EmptyArgUpdateFcn</li><li>EnableAxesStacking</li><li>EnableZStacking</li><li>EraseMode</li><li>EventObject</li><li>ExternalListenerHandles</li><li>HelpTopicKey</li><li>HostAxes</li><li>HostListenerHandles</li><li>IncludeRenderer</li><li>Invalid</li><li>IsDeserializing</li><li>MarkerHandle</li><li>MarkerHandleButtonDownFcn</li><li>Orientation</li><li>OrientationMode</li><li>OrientationPropertyListener</li><li>OriginalDoubleBufferState</li><li>PixelBounds</li><li>PointsOffset</li><li>Position</li><li>SelfListenerHandles</li><li>Serializable</li><li>TextBoxHandle</li><li>TextBoxHandleButtonDownFcn</li><li>Version</li><li>ViewStyle</li><li>XLimInclude</li><li>YLimInclude</li><li>ZLimInclude</li><li>ZStackMinimum</li><li>uistate</li></ul><p>As can be seen, if we really want, we can always use the <b>MarkerHandle</b> or <b>TextBoxHandle</b> directly.</p><h3 id="Deleting">Deleting data tips</h3><p>To delete a specific data-tip, simply call the cursor mode&#8217;s <i>removeDataCursor()</i> method; to delete all data-tips, call its <i>removeAllDataCursors()</i> method:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Delete the current data-tip</span>
cursorMode.<span style="">removeDataCursor</span><span style="color: #080;">&#40;</span>cursorMode.<span style="">CurrentDataCursor</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">% Delete all data-tips</span>
cursorMode.<span style="">removeAllDataCursors</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span></pre></div></div><p>Have you used plot data-tips in some nifty way? If so, please share your experience in a <a
href="http://undocumentedmatlab.com/blog/controlling-plot-data-tips/#respond">comment</a> below.</p><p>p.s. &#8211; did you notice that Java was not mentioned anywhere above? Mode managers use pure-Matlab functionality.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/accessing-plot-brushed-data/' rel='bookmark' title='Accessing plot brushed data'>Accessing plot brushed data</a> <small>Plot data brushing can be accessed programmatically using very simple pure-Matlab code...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-linesmoothing-property/' rel='bookmark' title='Plot LineSmoothing property'>Plot LineSmoothing property</a> <small>LineSmoothing is a hidden and undocumented plot line property that creates anti-aliased (smooth unpixelized) lines in Matlab plots...</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/com-activex-tips/' rel='bookmark' title='COM/ActiveX tips &amp; tricks'>COM/ActiveX tips &#038; tricks</a> <small>This article describes several little-known tips useful for COM / ActiveX programming in Matlab...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/controlling-plot-data-tips/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Bug and workaround in timeseries plot</title><link>http://undocumentedmatlab.com/blog/bug-and-workaround-in-timeseries-plot/</link> <comments>http://undocumentedmatlab.com/blog/bug-and-workaround-in-timeseries-plot/#comments</comments> <pubDate>Wed, 07 Sep 2011 18:41:33 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Low risk of breaking in future versions]]></category> <category><![CDATA[Semi-documented function]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Internal component]]></category> <category><![CDATA[Pure Matlab]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2428</guid> <description><![CDATA[Matlab's internal hgconvertunits function has a bug that affects timeseries plots. Luckily there is a simple workaround.<pre> </pre>Related posts:<ol><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/plot-performance/' rel='bookmark' title='Plot performance'>Plot performance</a> <small>Undocumented inner plot mechanisms can be used to significantly improved plotting performance...</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><li><a
href='http://undocumentedmatlab.com/blog/controlling-plot-data-tips/' rel='bookmark' title='Controlling plot data-tips'>Controlling plot data-tips</a> <small>Data-tips are an extremely useful plotting tool that can easily be controlled programmatically....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>I was about to write on something completely different today, when I discovered the following internal Matlab bug (and workaround) that I thought could be useful to some readers, so I changed my plans and the original article will see light next week (or the next, or whenever&#8230;).</p><h3 id="Bug">The bug</h3><p>Try the following code snippet:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">today = <span style="color: #0000FF;">fix</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">now</span><span style="color: #080;">&#41;</span>;
ts = timeseries<span style="color: #080;">&#40;</span><span style="color: #0000FF;">rand</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">201</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF;">datestr</span><span style="color: #080;">&#40;</span>today-<span style="color: #33f;">200</span><span style="color: #F0F;">:</span>today<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">figure</span>;
hPanel = uipanel<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'norm'</span>,<span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span>.2,.2,.5,.5<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
hAxes = <span style="color: #0000FF;">axes</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Parent'</span>,hPanel, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'norm'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>ts, <span style="color:#A020F0;">'Parent'</span>,hAxes<span style="color: #080;">&#41;</span>;</pre></div></div><p>As you can see, the plot&#8217;s x-tick labels are all bunched together:<br
/><center><div
class="wp-caption aligncenter" style="width: 290px"><img
alt="Timeseries plot bug (note x tick labels)" src="http://UndocumentedMatlab.com/images/ts_plot_bug_before.png" title="Timeseries plot bug (note x tick labels)" width="280" /><p
class="wp-caption-text">Timeseries plot bug (note x tick labels)</p></div></center></p><h3 id="Workaround">The workaround</h3><p>I debugged the problem and traced it to line #317 of &#8230;\R2011b\toolbox\matlab\timeseries\@timeseries\plot.m (in the R2011b installation):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">axpos = hgconvertunits<span style="color: #080;">&#40;</span>f,<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>ax,<span style="color:#A020F0;">'Position'</span><span style="color: #080;">&#41;</span>,<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>ax,<span style="color:#A020F0;">'Units'</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'normalized'</span>,f<span style="color: #080;">&#41;</span>;</pre></div></div><p>This line uses <i><b>hgconvertunits</b></i> to get the figure-based normalized units of the axes. <i><b>hgconvertunits</b></i> is an internal semi-documented helper function that convert a Handle-Graphics position vector in one set of units into another position vector in other units based on some other reference HG object. For example, it can tell me what the position of an internal control is in normalized figure units, even if the control is deeply nested within multiple panels. Which is exactly what it tries to do in this case.</p><p>Unfortunately, <i><b>hgconvertunits</b></i> apparently has a bug that causes it to return the parent-based normalized position values rather than the figure-based ones in this particular case. This causes the function to think that the axes is much bigger than it really is, and therefore it uses more x-tick labels than it should.</p><p>This <i><b>hgconvertunits</b></i> bug may very possibly affect numerous other Matlab functions that use this built-in function. The correct fix is to fix the <i><b>hgconvertunits</b></i> function. However, since this is an non-modifiable internal function, I found the following workaround for the <i><b>timeseries</b></i> plot only, by replacing the above line with the following:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">axpos = hgconvertunits<span style="color: #080;">&#40;</span>f,getpixelposition<span style="color: #080;">&#40;</span>ax,f<span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'pixel'</span>,<span style="color:#A020F0;">'normalized'</span>,f<span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 291px"><img
alt="Timeseries plot fix (note x tick labels)" src="http://UndocumentedMatlab.com/images/ts_plot_bug_after.png" title="Timeseries plot fix (note x tick labels)" width="281" /><p
class="wp-caption-text">Timeseries plot fix (note x tick labels)</p></div></center></p><p>Now the x-tick labels appear nicely, including during resize and zooming.</p><p>This problem occurs on R2011b. I was able to recreate the same problem and use the same fix back to R2010b. I do not know how far earlier the bug goes&#8230;</p><p>I reported the problem today (1-FEM0L7 for anyone interested). If I learn of a patch for <i><b>hgconvertunits</b></i> I will post an addendum on this page.</p><p><pre> </pre>Related posts:<ol><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/plot-performance/' rel='bookmark' title='Plot performance'>Plot performance</a> <small>Undocumented inner plot mechanisms can be used to significantly improved plotting performance...</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><li><a
href='http://undocumentedmatlab.com/blog/controlling-plot-data-tips/' rel='bookmark' title='Controlling plot data-tips'>Controlling plot data-tips</a> <small>Data-tips are an extremely useful plotting tool that can easily be controlled programmatically....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/bug-and-workaround-in-timeseries-plot/feed/</wfw:commentRss> <slash:comments>2</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>3</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>Multi-column (grid) legend</title><link>http://undocumentedmatlab.com/blog/multi-column-grid-legend/</link> <comments>http://undocumentedmatlab.com/blog/multi-column-grid-legend/#comments</comments> <pubDate>Mon, 07 Feb 2011 18:00:04 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Guest bloggers]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Hidden property]]></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[Adrian Cherry]]></category> <category><![CDATA[Listener]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[scribe]]></category> <category><![CDATA[Undocumented property]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2071</guid> <description><![CDATA[This article explains how to use undocumented axes listeners for implementing multi-column plot legends<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/legend-semi-documented-feature/' rel='bookmark' title='Legend &#8216;-DynamicLegend&#8217; semi-documented feature'>Legend &#8216;-DynamicLegend&#8217; semi-documented feature</a> <small>The built-in Matlab legend function has a very useful semi-documented feature for automatic dynamic update, which is explained here....</small></li><li><a
href='http://undocumentedmatlab.com/blog/multi-line-tooltips/' rel='bookmark' title='Multi-line tooltips'>Multi-line tooltips</a> <small>Multi-line tooltips are very easy to set up, once you know your way around a few undocumented hiccups....</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/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></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p><i>I would like to welcome guest blogger Adrian Cherry. Adrian will describe a very handy utility that shows how basic built-in Matlab functions can be improved and customized by just a bit of fiddling under Matlab&#8217;s hood.</i></p><h3 id="Legend">Legend Plotting</h3><p>Whilst I enjoy using the many time saving features of Matlab, one area where I feel it suffers is the technical plotting and annotation. This tale relates the development of a legend plotting routine, <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/29248-gridlegend-a-multi-column-format-for-legends">gridLegend</a>, in an effort to improve the presentation.</p><p>In my day job we have a requirement to condense a large quantity of data onto summary charts. However, there is only so much data consolidation possible before you start losing the information required. We often need to plot 40 or 50 lines of test data to visualize trends or outliers, using the legend to identify the number of test hours against each test specimen.</p><p>Using the standard Matlab <i><b>legend</b></i> function resulted in a long legend over twice the size of the associated plot:</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="Standard Matlab legend" src="http://UndocumentedMatlab.com/images/Legend1.png" title="Standard Matlab legend" width="450" height="337" /><p
class="wp-caption-text">Standard Matlab legend</p></div></center></p><p>I wanted some way of generating a more compact legend format.</p><p>Fortunately earlier in the year, an entry on Matlab Central allowing a multi-column legend to be generated was posted, <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/27389-columnlegend">columnlegend</a>. Although lacking some features, columnlegend gave me a good start on developing what I wanted for a multi column legend, culminating in <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/29248-gridlegend-a-multi-column-format-for-legends">gridLegend</a>:</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="Multi-column legend" src="http://UndocumentedMatlab.com/images/Legend2.png" title="Multi-column legend" width="450" height="398" /><p
class="wp-caption-text">Multi-column legend</p></div></center></p><h3 id="Undocumented">Delving into the Undocumented Matlab</h3><p>So where is the link with undocumented Matlab?</p><p>As mentioned in the original columnlegend entry, it was relatively simple to redraw the legend as required on the screen. However, as soon as the figure was printed or exported to an image file, internal Matlab workings would redraw the figure, including the legend, thereby undoing my careful legend crafting, squeezing it back into one column (Yuck!):</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="Matlab-reverted multi-column legend" src="http://UndocumentedMatlab.com/images/Legend3.png" title="Matlab-reverted multi-column legend" width="450" height="398" /><p
class="wp-caption-text">Matlab-reverted multi-column legend</p></div></center></p><p>As we wanted to automatically output images files, I had to delve into the hidden areas of Matlab to try to solve this problem.</p><p>My initial thought was to find out where the figure got redrawn for printing or export and override the standard legend call with a call to my new function. I couldn&#8217;t find the obvious culprit, stepping as far as I could through the print function there didn&#8217;t appear to be any call to the legend function.</p><p>In my search for information on how the legend worked I found the undocumented Matlab article about generating <a
target="_blank" href="http://UndocumentedMatlab.com/blog/legend-semi-documented-feature/">dynamic legends</a>. This dynamic-legend post covered details about attaching a listener to a child of the legend axes, in Matlab the legend function creates its own set of axes on the figure to display the legend.</p><p>Armed with the information that legend axes objects could have listeners attached, I considered that these might be the source of redrawing the legend for printing. So with the legend I had generated I took a look at what listeners were attached, using the undocumented hidden axes property <b>ScribeLegendListeners</b>:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; legendListener = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'ScribeLegendListeners'</span><span style="color: #080;">&#41;</span>
legendListener = 
        fontname<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#93;</span>
        fontsize<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#93;</span>
      fontweight<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#93;</span>
       fontangle<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#93;</span>
       linewidth<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#93;</span>
         deleted<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#93;</span>
    proxydeleted<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#93;</span></pre></div></div><p>The font size and line positioning were all being redrawn for printing so this was potentially the source of my problem. However I&#8217;d not looked at a <i><b>handle.listener</b></i> before, so a little further digging was required:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">K&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>legendListener.<span style="">fontname</span><span style="color: #080;">&#41;</span>
      SourceObject<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 schema.<span style="">prop</span><span style="color: #080;">&#93;</span>
         Container<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">axes</span><span style="color: #080;">&#93;</span>
         EventType<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'PropertyPostSet'</span>
          Callback<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>2x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
    CallbackTarget<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
           Enabled<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span></pre></div></div><p>The option <b>Enabled</b> immediately drew my attention, and so the following lines were added to my gridLegend function to switch off these listeners and apply it back to the legend:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">LL = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'ScribeLegendListeners'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>LL.<span style="">fontname</span>,<span style="color:#A020F0;">'enabled'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>LL.<span style="">fontsize</span>,<span style="color:#A020F0;">'enabled'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>LL.<span style="">fontweight</span>,<span style="color:#A020F0;">'enabled'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>LL.<span style="">fontangle</span>,<span style="color:#A020F0;">'enabled'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>LL.<span style="">linewidth</span>,<span style="color:#A020F0;">'enabled'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'ScribeLegendListeners'</span>,LL<span style="color: #080;">&#41;</span>;</pre></div></div><p>Finally allowing me to output the image files with a multi-column legend:</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="Printed multi-column legend" src="http://UndocumentedMatlab.com/images/Legend4.jpg" title="Printed multi-column legend" width="450" height="363" /><p
class="wp-caption-text">Printed multi-column legend</p></div></center></p><p>So my thanks to the contributors on Matlab Central who enabled me to get started on gridLegend and to Yair for collating the many nuggets of information on Undocumented Matlab which allowed me to complete the function and get it posted on Matlab Central.</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="Multi-column legend in action" src="http://UndocumentedMatlab.com/images/gridLegend.jpg" title="Multi-column legend in action" width="450" height="300" /><p
class="wp-caption-text">Multi-column legend in action</p></div></center></p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/legend-semi-documented-feature/' rel='bookmark' title='Legend &#8216;-DynamicLegend&#8217; semi-documented feature'>Legend &#8216;-DynamicLegend&#8217; semi-documented feature</a> <small>The built-in Matlab legend function has a very useful semi-documented feature for automatic dynamic update, which is explained here....</small></li><li><a
href='http://undocumentedmatlab.com/blog/multi-line-tooltips/' rel='bookmark' title='Multi-line tooltips'>Multi-line tooltips</a> <small>Multi-line tooltips are very easy to set up, once you know your way around a few undocumented hiccups....</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/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></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/multi-column-grid-legend/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>handle2struct, struct2handle &amp; Matlab 8.0</title><link>http://undocumentedmatlab.com/blog/handle2struct-struct2handle-and-matlab-8/</link> <comments>http://undocumentedmatlab.com/blog/handle2struct-struct2handle-and-matlab-8/#comments</comments> <pubDate>Wed, 29 Dec 2010 18:00:56 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Handle graphics]]></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[GUIDE]]></category> <category><![CDATA[HG2]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Menubar]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[Toolbar]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2023</guid> <description><![CDATA[This article explains how we can use a couple of undocumented functions in Matlab GUI, and what we can learn from this about Matlab's future.<pre> </pre>Related posts:<ol><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/matlab-layout-managers-uicontainer-and-relatives/' rel='bookmark' title='Matlab layout managers: uicontainer and relatives'>Matlab layout managers: uicontainer and relatives</a> <small>Matlab contains a few undocumented GUI layout managers, which greatly facilitate handling GUI components in dynamically-changing figures....</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/' rel='bookmark' title='Matlab and the Event Dispatch Thread (EDT)'>Matlab and the Event Dispatch Thread (EDT)</a> <small>The Java Swing Event Dispatch Thread (EDT) is very important for Matlab GUI timings. This article explains the potential pitfalls and their avoidance using undocumented Matlab functionality....</small></li><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></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Last week I explained that <a
target="_blank" href="http://undocumentedmatlab.com/blog/fig-files-format/">FIG files are simply MAT files in disguise</a>. Today, we look under the hood of Matlab&#8217;s <i><b>hgsave</b></i> function, which is used to save FIG files. We shall see that this is both useful and illuminating vis-a-vis Matlab&#8217;s future.</p><h3 id="handle2struct">handle2struct</h3><p>Under the hood, <i><b>hgsave</b></i> uses the <a
target="_blank" href="http://undocumentedmatlab.com/blog/legend-semi-documented-feature/#Semi-documented">semi-documented</a> built-in <i><b>handle2struct</b></i> function to convert the figure handle into a Matlab <i><b>struct</b></i> that is then stored with a simple <i><b>save</b></i> (the same function that saves MAT files) function call.</p><p>The fact that <i><b>handle2struct</b></i> is semi-documented means that the function is explained in a help comment (which can be seen via the <i><b>help</b></i> command), that is nonetheless not part of the official doc sections. It is an unsupported feature originally intended only for internal Matlab use (which of course doesn&#8217;t mean we can&#8217;t use it).</p><p><i><b>handle2struct</b></i> merits a dedicated mention, since I can envision several use-cases for storing only a specific GUI handle (for example, a <i><b>uipanel</b></i>, a specific graph, or a set of GUI controls&#8217; state). In this case, all we need to do is to call <i><b>handle2struct</b></i> with the requested parent handle, then <i><b>save</b></i> the returned structure. So simple, so powerful. <i><b>handle2struct</b></i> automatically returns all the non-default property information, recursively in all the handle&#8217;s children.</p><p>Note that features that are not properties of displayed handles (camera position, 3D rotation/pan/zoom states, annotations, axes-linking etc.) are not processed by <i><b>handle2struct</b></i>. For storing the states of these features, you need to use some specific handling &#8211; see the code within %matlabroot%\toolbox\matlab\graphics\private\hgsaveStructDbl.m for details. Basically, hgsaveStructDbl.m reads the state of all these features and temporarily stores them in the base handle&#8217;s <strong>ApplicationData</strong> property; <i><b>handle2struct</b></i> then reads them as any other regular handle property data, and then hgsaveStructDbl.m clears the temporary data from the handle&#8217;s <strong>ApplicationData</strong>. We can use the same trick for any other application state, of course.</p><h3 id="struct2handle">struct2handle</h3><p><i><b>handle2struct</b></i> has a reverse function &#8211; the semi-documented <i><b>struct2handle</b></i>. I use it for creating dynamic preference panels: As in Matlab&#8217;s Preferences window, I have a list of preference topics and a set of corresponding options panels. In my case, it was easy to design each panel as a separate FIG file using GUIDE. In run-time, I simply load the relevant panel from its FIG file as described above, and place it onscreen in a dedicated <i><b>uipanel</b></i> using <i><b>struct2handle</b></i>. This enables very easy maintenance of preference panels, without sacrificing any functionality.</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="Matlab's preferences panels" src="http://UndocumentedMatlab.com/images/FIG_MAT.png" title="Matlab's preferences panels" width="450" height="274" /><p
class="wp-caption-text">Matlab's preferences panels</p></div></center></p><p>Figure menus and toolbars are not normally stored by <i><b>hgsave</b></i>, unless you use the optional &#8216;all&#8217; parameter (and correspondingly in <i><b>hgload</b></i>, if you choose to use it). <i><b>handle2struct</b></i> and <i><b>handle2struct</b></i> accept the same optional &#8216;all&#8217; parameter as <i><b>hgsave</b></i> and <i><b>hgload</b></i>. Unfortunately, a warning message indicates that this option will be discontinued in some future Matlab version.</p><p>Which brings us to our final topic for today:</p><h3 id="Matlab8">Matlab 8: Boldly going where no FIG has gone before&#8230;</h3><p>Remember my post earlier this year about the <a
target="_blank" href="http://undocumentedmatlab.com/blog/matlab-hg2/">new HG2 mechanism</a>? I speculated that when MathWorks decides to release HG2, it will define this as a major Matlab release and label it Matlab 8.0.</p><p>The source code in hgsave.m appears to confirm my speculation. Here is the relevant code section (slightly edited for clarity), which speaks for itself:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Decide which save code path to use</span>
<span style="color: #0000FF;">if</span> ~feature<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'HGUsingMatlabClasses'</span><span style="color: #080;">&#41;</span>   <span style="color: #228B22;">% &lt;== existing HG</span>
    <span style="color: #228B22;">% Warn if user passed in 'all' flag</span>
    <span style="color: #0000FF;">if</span> SaveAll
        <span style="color: #0000FF;">warning</span><span style="color: #080;">&#40;</span> <span style="color:#A020F0;">'MATLAB:hgsave:DeprecatedOption'</span>, <span style="color: #F0F;">...</span>
            <span style="color:#A020F0;">'The '</span><span style="color:#A020F0;">'all'</span><span style="color:#A020F0;">' option to hgsave will be removed in a future release.'</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
    hgS = hgsaveStructDbl<span style="color: #080;">&#40;</span>h, SaveAll<span style="color: #080;">&#41;</span>;
    SaveVer = <span style="color:#A020F0;">'070000'</span>;
    SaveOldFig = <span style="color: #0000FF;">true</span>;
&nbsp;
<span style="color: #0000FF;">else</span>   <span style="color: #228B22;">% &lt;== HG2</span>
&nbsp;
    <span style="color: #228B22;">% Warn if user passed in 'all' flag</span>
    <span style="color: #0000FF;">if</span> SaveAll
        <span style="color: #0000FF;">warning</span><span style="color: #080;">&#40;</span> <span style="color:#A020F0;">'MATLAB:hgsave:DeprecatedOption'</span>, <span style="color: #F0F;">...</span>
            <span style="color:#A020F0;">'The '</span><span style="color:#A020F0;">'all'</span><span style="color:#A020F0;">' option to hgsave has been removed.'</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
    <span style="color: #0000FF;">if</span> SaveOldFig
        hgS = hgsaveStructClass<span style="color: #080;">&#40;</span>h<span style="color: #080;">&#41;</span>;
        SaveVer = <span style="color:#A020F0;">'080000'</span>;
    <span style="color: #0000FF;">else</span>
        hgO = hgsaveObject<span style="color: #080;">&#40;</span>h<span style="color: #080;">&#41;</span>;
        SaveVer = <span style="color:#A020F0;">'080000'</span>;
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">% Revision encoded as 2 digits for major revision,</span>
<span style="color: #228B22;">% 2 digits for minor revision, and 2 digits for</span>
<span style="color: #228B22;">% patch revision.  This is the minimum revision</span>
<span style="color: #228B22;">% required to fully support the file format.</span>
<span style="color: #228B22;">% e.g. 070000 means 7.0.0</span></pre></div></div><p>As can be seen, when Matlab starts using HG2 (perhaps in 2011?), the top-level structure node will be called &#8220;hgS_080000&#8243;, indicating Matlab 8.0. QED.</p><p>As a side-note, note that in HG2/Matlab8, although the comment about using &#8216;all&#8217; indicates that it has been removed, in practice it is still accepted (although not being used). This will enable your code to be backward-compatible whenever HG2 launches, and future-compatible today.</p><p>Have you used <i><b>handle2struct</b></i> or <i><b>struct2handle</b></i>? If so, please share your experience in a <a
href="http://undocumentedmatlab.com/blog/handle2struct-struct2handle-and-matlab-8/#respond">comment</a>.</p><p><em>Let the upcoming 2011 be a year filled with revelations, announcements and fulfillment! Happy New Year everybody!</em></p><p><pre> </pre>Related posts:<ol><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/matlab-layout-managers-uicontainer-and-relatives/' rel='bookmark' title='Matlab layout managers: uicontainer and relatives'>Matlab layout managers: uicontainer and relatives</a> <small>Matlab contains a few undocumented GUI layout managers, which greatly facilitate handling GUI components in dynamically-changing figures....</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/' rel='bookmark' title='Matlab and the Event Dispatch Thread (EDT)'>Matlab and the Event Dispatch Thread (EDT)</a> <small>The Java Swing Event Dispatch Thread (EDT) is very important for Matlab GUI timings. This article explains the potential pitfalls and their avoidance using undocumented Matlab functionality....</small></li><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></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/handle2struct-struct2handle-and-matlab-8/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>FIG files format</title><link>http://undocumentedmatlab.com/blog/fig-files-format/</link> <comments>http://undocumentedmatlab.com/blog/fig-files-format/#comments</comments> <pubDate>Wed, 22 Dec 2010 18:00:56 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Low risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Pure Matlab]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2013</guid> <description><![CDATA[FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/reading-non-latin-text-files/' rel='bookmark' title='Reading non-Latin text files'>Reading non-Latin text files</a> <small>A workaround that enables reading non-Latin text files in Matlab is shown...</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/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/modifying-default-toolbar-menubar-actions/' rel='bookmark' title='Modifying default toolbar/menubar actions'>Modifying default toolbar/menubar actions</a> <small>The default Matlab figure toolbar and menu actions can easily be modified using simple pure-Matlab code. This article explains how....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>A short while ago, a StackOverflow user asked <a
target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/2976505/how-can-i-extract-data-from-a-fig-file-in-matlab">how to extract data from FIG files in Matlab</a>. The answer to this question is easy, but I wish to use the opportunity to show how this can be useful in Matlab applications.</p><h3 id="The_Need">The need: load a FIG without displaying it</h3><p>In data-processing applications, we often present data in graphs that can then be manipulated and saved for later use. In Matlab, saving is done interactively (via the figure&#8217;s File/Save menu option or via the figure&#8217;s Save toolbar button), or programmatically (via the <i><b>hgsave</b></i> function). In all cases, the data is stored in a *.FIG file (the FIG extension can actually be changed, but I really don&#8217;t see why).</p><p>The point is that in order to re-load the stored data, we need to use <i><b>hgload</b></i>, which has a nasty side-effect of actually displaying the stored figure.</p><p>This is bad in terms of performance and memory, especially for heavily-laden GUI figures, not to mention the fact that sometimes we do not want to display the GUI at all. We often just need to extract a sub-set of the stored information (for example, the plot values), <strong>without</strong> having to display the figure.</p><h3 id="FIG_Format">The answer: FIGs are simply MATs in disguise</h3><p>Here&#8217;s where the undocumented stuff enters:</p><p>It seems that a FIG file is simply a hierarchical structure of all the non-default properties of the stored figure and its descendant handles, all this stored within a simple MAT file.</p><p>This is hinted in several places, for example in <i><b>hgsave</b></i>&#8216;s doc page, and in the MAT-file preferences panel:</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="MAT-file preferences (note the FIG clarification)" src="http://UndocumentedMatlab.com/images/FIG_MAT.png" title="MAT-file preferences (note the FIG clarification)" width="450" height="274" /><p
class="wp-caption-text">MAT-file preferences (note the FIG clarification)</p></div></center></p><p>Knowing this, we can easily load the data, <strong>without</strong> displaying the figure, by using <i><b>load</b>(filename,&#8217;-mat&#8217;)</i> rather than <i><b>hgload</b></i>. For example:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Create and store a simple plot figure</span>
&gt;&gt; <span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Name'</span>,<span style="color:#A020F0;">'Test #1'</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">9</span>, <span style="color: #0000FF;">sqrt</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">9</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&gt;&gt; hgsave<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'testFig'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Load the figure data</span>
&gt;&gt; d = <span style="color: #0000FF;">load</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'testFig.fig'</span>,<span style="color:#A020F0;">'-mat'</span><span style="color: #080;">&#41;</span>
d = 
    hgS_070000<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>   <span style="color: #228B22;">% a Matlab 7 figure</span>
&nbsp;
<span style="color: #228B22;">% Investigate the figure data</span>
&gt;&gt; d.<span style="">hgS_070000</span>
<span style="color: #0000FF;">ans</span> = 
          <span style="color: #0000FF;">type</span><span style="color: #F0F;">:</span> <span style="color:#A020F0;">'figure'</span>
        handle<span style="color: #F0F;">:</span> <span style="color: #33f;">1</span>
    properties<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
      children<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
       special<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; d.<span style="">hgS_070000</span>.<span style="">children</span>
<span style="color: #0000FF;">ans</span> = 
          <span style="color: #0000FF;">type</span><span style="color: #F0F;">:</span> <span style="color:#A020F0;">'axes'</span>
        handle<span style="color: #F0F;">:</span> <span style="color: #33f;">176.08251953125</span>
    properties<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
      children<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
       special<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>4x1 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; d.<span style="">hgS_070000</span>.<span style="">children</span>.<span style="">children</span>
<span style="color: #0000FF;">ans</span> = 
          <span style="color: #0000FF;">type</span><span style="color: #F0F;">:</span> <span style="color:#A020F0;">'graph2d.lineseries'</span>
        handle<span style="color: #F0F;">:</span> <span style="color: #33f;">177.0830078125</span>
    properties<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
      children<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
       special<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; d.<span style="">hgS_070000</span>.<span style="">children</span>.<span style="">children</span>.<span style="">properties</span>
<span style="color: #0000FF;">ans</span> = 
              Color<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;">1</span><span style="color: #080;">&#93;</span>
              XData<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">2</span> <span style="color: #33f;">3</span> <span style="color: #33f;">4</span> <span style="color: #33f;">5</span> <span style="color: #33f;">6</span> <span style="color: #33f;">7</span> <span style="color: #33f;">8</span> <span style="color: #33f;">9</span><span style="color: #080;">&#93;</span>
              YData<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">1.4142</span> <span style="color: #33f;">1.7321</span> <span style="color: #33f;">2</span> <span style="color: #33f;">2.2361</span> <span style="color: #33f;">2.4495</span> <span style="color: #33f;">2.6458</span> <span style="color: #33f;">2.8284</span> <span style="color: #33f;">3</span><span style="color: #080;">&#93;</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>
        XDataJitter<span style="color: #F0F;">:</span> <span style="color: #33f;">0</span>
          XDataMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'manual'</span>
      ObeyXDataMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'auto'</span>
                <span style="color: #F0F;">...</span>
&nbsp;
<span style="color: #228B22;">% Extract plot data</span>
&gt;&gt; YData = d.<span style="">hgS_070000</span>.<span style="">children</span>.<span style="">children</span>.<span style="">properties</span>.<span style="">YData</span>
YData =
  <span style="color: #33f;">1.0000</span>  <span style="color: #33f;">1.4142</span>  <span style="color: #33f;">1.7321</span>  <span style="color: #33f;">2.0000</span>  <span style="color: #33f;">2.2361</span>  <span style="color: #33f;">2.4495</span>  <span style="color: #33f;">2.6458</span>  <span style="color: #33f;">2.8284</span>  <span style="color: #33f;">3.0000</span></pre></div></div><p>We see a couple of interesting things in this simple example:</p><p>First, note that the top-level structure node is called &#8220;hgS_070000&#8243; &#8211; we&#8217;ll dig into this next week. Basically, it indicates that the structure holds a Matlab 7 figure.</p><p>Secondly, we see <a
target="_blank" href="http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/">hidden/undocumented properties</a> of the stored objects (for example, the lineseries&#8217; <strong>XDataJitter</strong> and <strong>ObeyXDataMode</strong> properties). <strong>ApplicationData</strong> is such a hidden handle, which is widely used as a substitute for any handle&#8217;s <strong>UserData</strong> property (the built-in <i><b>setappdata</b></i> and <i><b>getappdata</b></i> functions are simply wrappers for accessing this property using standard <i><b>set</b></i> and <i><b>get</b></i> functions).</p><p>Have you used the FIG/MAT feature for any useful functionality? If so, please do share your experience in a <a
href="http://undocumentedmatlab.com/blog/fig-files-format/#respond">comment</a>.</p><p><em>Next week, I will explain how looking under <i><b>hgsave</b></i>&#8216;s hood leads to useful functions and to an interesting insight about Matlab&#8217;s future. Merry Christmas everybody!</em></p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/reading-non-latin-text-files/' rel='bookmark' title='Reading non-Latin text files'>Reading non-Latin text files</a> <small>A workaround that enables reading non-Latin text files in Matlab is shown...</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/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/modifying-default-toolbar-menubar-actions/' rel='bookmark' title='Modifying default toolbar/menubar actions'>Modifying default toolbar/menubar actions</a> <small>The default Matlab figure toolbar and menu actions can easily be modified using simple pure-Matlab code. This article explains how....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/fig-files-format/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Panel-level uicontrols</title><link>http://undocumentedmatlab.com/blog/panel-level-uicontrols/</link> <comments>http://undocumentedmatlab.com/blog/panel-level-uicontrols/#comments</comments> <pubDate>Wed, 24 Nov 2010 18:00:53 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[GUI]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Low risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[UI controls]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[TitleHandle]]></category> <category><![CDATA[uicontrol]]></category> <category><![CDATA[Undocumented property]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=1976</guid> <description><![CDATA[Matlab's uipanel contains a hidden handle to the title label, which can be modified into a checkbox or radio-button control<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/gui-integrated-html-panel/' rel='bookmark' title='GUI integrated HTML panel'>GUI integrated HTML panel</a> <small>Simple HTML can be presented in a Java component integrated in Matlab GUI, without requiring the heavy browser control....</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/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><li><a
href='http://undocumentedmatlab.com/blog/gui-integrated-browser-control/' rel='bookmark' title='GUI integrated browser control'>GUI integrated browser control</a> <small>A fully-capable browser component is included in Matlab and can easily be incorporated in regular Matlab GUI applications. This article shows how....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>In one of my larger Matlab applications &#8211; <em>Integration-lab Debriefing System</em> (IDS, which shall be described in a future dedicated article) &#8211; I wanted to present a panel-level checkbox that applies to the entire panel contents. In my particular case, the IDS <i><b>uipanel</b></i> contained a Java table (another future topic) with multiple selectable rows, and I needed a global checkbox that selects all (or none) of them at once:</p><p><center><div
class="wp-caption aligncenter" style="width: 138px"><img
alt='Panel-level ("Objects") checkbox' src="http://UndocumentedMatlab.com/images/IDS_Main_Tabs.png" title='Panel-level ("Objects") checkbox' width="128" height="107" /><p
class="wp-caption-text">Panel-level ("Objects") checkbox</p></div></center></p><p>One way to do this is to calculate the checkbox&#8217;s desired position relative to the <i><b>uipanel</b></i> and place a regular checkbox-style <i><b>uicontrol</b></i> there. The checkbox can even be made a child of the <i><b>uipanel</b></i> with &#8216;normalized&#8217; units, thereby moving and resizing it together with its <i><b>uipanel</b></i> parent when the later is moved or resized.</p><p>But there&#8217;s a much simpler method that want to share. It relies on the undocumented fact that the <i><b>uipanel</b></i>&#8216;s title label is a simple hidden <i><b>uicontrol</b></i> child of the <i><b>uipanel</b></i> handle. This <i><b>uicontrol</b></i> handle can be found and simply transformed from a &#8216;style&#8217;='text&#8217; control into a &#8216;style&#8217;='checkbox&#8217; control, as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Prepare the panel</span>
hPanel = uipanel<span style="color: #080;">&#40;</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.2</span>,<span style="color: #33f;">0.4</span>,<span style="color: #33f;">0.4</span><span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'title'</span>,<span style="color:#A020F0;">'Objects'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Get the title label's handle</span>
<span style="color: #0000FF;">warning</span> off MATLAB<span style="color: #F0F;">:</span>Uipanel<span style="color: #F0F;">:</span>HiddenImplementation  <span style="color: #228B22;">% turn off warning</span>
hTitle = <span style="color: #0000FF;">setdiff</span><span style="color: #080;">&#40;</span>findall<span style="color: #080;">&#40;</span>hPanel<span style="color: #080;">&#41;</span>,hPanel<span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% retrieve title handle</span>
hTitle = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hPanel,<span style="color:#A020F0;">'TitleHandle'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% alternative, uses hidden prop</span>
&nbsp;
<span style="color: #228B22;">% Modify the uicontrol style; add 20 pixel space for the checkbox</span>
newPos = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hTitle,<span style="color:#A020F0;">'position'</span><span style="color: #080;">&#41;</span> + <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">20</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>;  <span style="color: #228B22;">% in pixels</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hTitle, <span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'checkbox'</span>, <span style="color:#A020F0;">'value'</span>,<span style="color: #33f;">1</span>, <span style="color:#A020F0;">'pos'</span>,newPos<span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 130px"><img
alt="Panel-level checkbox" src="http://UndocumentedMatlab.com/images/IDS_Main_Checkbox.png" title="Panel-level checkbox" width="120" height="70" /><p
class="wp-caption-text">Panel-level checkbox</p></div></center></p><p>Note that we can retrieve the title handle using either the <i><b>uipanel</b></i>&#8216;s hidden property <b>TitleHandle</b>, or by scanning the panel&#8217;s children using <i><b>findall</b></i>. I prefer the <b>TitleHandle</b> approach because it does not require modification (minor as it might be) when the panel already contains other children.</p><p>The down-side is that since <b>TitleHandle</b> is an undocumented hidden property, it may change its name, its behavior or even be removed in some future Matlab release. In fact, there&#8217;s even a Matlab warning about this, unless you turn it off using:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">warning</span> off MATLAB<span style="color: #F0F;">:</span>Uipanel<span style="color: #F0F;">:</span>HiddenImplementation</pre></div></div><p>We can use this approach for more complex options panels, as the following example illustrates. Here, we set radio-button controls rather than a checkbox control, and also modify the title color to blue:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Main panel and basic alternative control</span>
hPanelMain = uipanel<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span>.1,.1,.8,.8<span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'Title'</span>,<span style="color:#A020F0;">'Main'</span>, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'norm'</span><span style="color: #080;">&#41;</span>;
hAlt1 = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hPanelMain, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'norm'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span>.1,.8,.5,.1<span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'radio'</span>, <span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'Alternative #1'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Alternative options panel #2</span>
hAlt2 = uipanel<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hPanelMain, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'norm'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span>.07,.4,.5,.35<span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'title'</span>,<span style="color:#A020F0;">'Alternative #2'</span><span style="color: #080;">&#41;</span>;
hAlt2Title = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAlt2, <span style="color:#A020F0;">'TitleHandle'</span><span style="color: #080;">&#41;</span>;
newPos = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAlt2Title,<span style="color:#A020F0;">'position'</span><span style="color: #080;">&#41;</span> + <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">20</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>;  <span style="color: #228B22;">% in pixels</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hAlt2Title, <span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'radio'</span>, <span style="color:#A020F0;">'pos'</span>,newPos<span style="color: #080;">&#41;</span>;
hAlt2a = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hAlt2, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'norm'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span>.2,.6,.7,.3<span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'checkbox'</span>, <span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'Option 1'</span><span style="color: #080;">&#41;</span>;
hAlt2b = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hAlt2, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'norm'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span>.2,.2,.7,.3<span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'checkbox'</span>, <span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'Option 2'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Alternative options panel #3</span>
hAlt3 = uipanel<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hPanelMain, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'norm'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span>.07,.05,.5,.3<span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'title'</span>,<span style="color:#A020F0;">'Alternative #3'</span><span style="color: #080;">&#41;</span>;
hAlt3Title = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAlt3, <span style="color:#A020F0;">'TitleHandle'</span><span style="color: #080;">&#41;</span>;
newPos = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAlt3Title,<span style="color:#A020F0;">'position'</span><span style="color: #080;">&#41;</span> + <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">20</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>;  <span style="color: #228B22;">% in pixels</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hAlt3Title, <span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'radio'</span>, <span style="color:#A020F0;">'pos'</span>,newPos, <span style="color:#A020F0;">'ForegroundColor'</span>,<span style="color:#A020F0;">'blue'</span><span style="color: #080;">&#41;</span>;
hAlt3a = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hAlt3, <span style="color:#A020F0;">'units'</span>,<span style="color:#A020F0;">'norm'</span>, <span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span>.2,.5,.7,.3<span style="color: #080;">&#93;</span>, <span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'popup'</span>, <span style="color:#A020F0;">'string'</span>,<span style="color: #080;">&#123;</span><span style="color:#A020F0;">'Option 3a'</span>,<span style="color:#A020F0;">'Option 3b'</span>,<span style="color:#A020F0;">'Option 3c'</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 431px"><img
alt="Advanced panel-level controls" src="http://UndocumentedMatlab.com/images/Panel_Controls.png" title="Advanced panel-level controls" width="421" height="373" /><p
class="wp-caption-text">Advanced panel-level controls</p></div></center></p><p>Note that since the hAlt2Title and hAlt3Title radio-buttons are children of their respective <i><b>uipanel</b></i> parents, we cannot use a simple <i><b>uibuttongroup</b></i> to group them in a mutual-exclusion group. Instead, we must use a dedicated callback function. This is actually quite easy:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Set the callback for all relevant radio-buttons</span>
hButtonGroup = <span style="color: #080;">&#91;</span>hAlt1, hAlt2Title, hAlt3Title<span style="color: #080;">&#93;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hButtonGroup, <span style="color:#A020F0;">'Callback'</span>, <span style="color: #080;">&#123;</span>@SelectionCb, hButtonGroup<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% This is the callback function that manages mutual exclusion</span>
<span style="color: #0000FF;">function</span> SelectionCb<span style="color: #080;">&#40;</span>hSrc,hEvent,hButtonGroup<span style="color: #080;">&#41;</span>
   otherButtons = <span style="color: #0000FF;">setdiff</span><span style="color: #080;">&#40;</span>hButtonGroup,hSrc<span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>otherButtons,<span style="color:#A020F0;">'value'</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hSrc,<span style="color:#A020F0;">'value'</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% needed to prevent de-selection</span>
<span style="color: #0000FF;">end</span></pre></div></div><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/gui-integrated-html-panel/' rel='bookmark' title='GUI integrated HTML panel'>GUI integrated HTML panel</a> <small>Simple HTML can be presented in a Java component integrated in Matlab GUI, without requiring the heavy browser control....</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/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><li><a
href='http://undocumentedmatlab.com/blog/gui-integrated-browser-control/' rel='bookmark' title='GUI integrated browser control'>GUI integrated browser control</a> <small>A fully-capable browser component is included in Matlab and can easily be incorporated in regular Matlab GUI applications. This article shows how....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/panel-level-uicontrols/feed/</wfw:commentRss> <slash:comments>6</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-02-04 03:57:18 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/tag/handle-graphics/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      2.530s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1328353036; expires=Sun, 03-Feb-2013 10:57:16 GMT; path=/
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Sat, 04 Feb 2012 10:57:18 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Sat, 04 Feb 2012 11:57:18 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               5a16b2364e2578da521a7c41c4f9386c
Content-Encoding:   gzip
-->
