<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Undocumented Matlab</title>
	
	<link>http://undocumentedmatlab.com</link>
	<description>Charting Matlab's unsupported hidden underbelly</description>
	<lastBuildDate>Mon, 20 May 2013 12:06:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/UndocumentedMatlab" /><feedburner:info uri="undocumentedmatlab" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>UndocumentedMatlab</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/UndocumentedMatlab" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsalloy.com/?rss=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.newsalloy.com/subrss3.gif">Subscribe with NewsAlloy</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://www.yourminis.com/subscribe.aspx?u=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.yourminis.com/images/addtoyourminisbadge.gif">Subscribe with Yourminis.com</feedburner:feedFlare><feedburner:feedFlare href="http://download.attensa.com/app/get_attensa.html?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.attensa.com/blogs/attensa/WindowsLiveWriter/BadgeredintoBadges_10C02/attensa_feed_button5.gif">Subscribe with Attensa for Outlook</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://hub.netomat.net/account/account.autoSubscribe.jspa?urls=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.netomat.net/blogger/images/icon_netomat_feedbutton.gif">Subscribe with netomat Hub</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.flurry.com/pushRssFeed.do?r=fb&amp;url=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.flurry.com/images/flurry_rss_logo2.gif">Subscribe with Flurry</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2FUndocumentedMatlab" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><feedburner:browserFriendly>Posts about undocumented, unsupported and hidden features in the Matlab environment. These range from the innocent property that was forgotten in the official documentation, to the truly hazardous don't-try-this-at-home internal settings.</feedburner:browserFriendly><item>
		<title>HG2 update</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/tIztzUrEpNA/</link>
		<comments>http://undocumentedmatlab.com/blog/hg2-update/#comments</comments>
		<pubDate>Thu, 16 May 2013 00:38:19 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Figure window]]></category>
		<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[Undocumented feature]]></category>
		<category><![CDATA[HG2]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Undocumented property]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3789</guid>
		<description><![CDATA[HG2 appears to be nearing release. It is now a stable mature system.  
<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/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/panel-level-uicontrols/' rel='bookmark' title='Panel-level uicontrols'>Panel-level uicontrols</a> <small>Matlab's uipanel contains a hidden handle to the title label, which can be modified into a checkbox or radio-button control...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/multi-column-grid-legend/' rel='bookmark' title='Multi-column (grid) legend'>Multi-column (grid) legend</a> <small>This article explains how to use undocumented axes listeners for implementing multi-column plot legends...</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Exactly three years ago, I posted information (<a target="_blank" href="http://undocumentedmatlab.com/blog/matlab-hg2/">here</a> and <a target="_blank" href="http://undocumentedmatlab.com/blog/new-information-on-hg2/">here</a>) about Matlab&#8217;s upcoming new graphics engine, so-called HG2 (<i>Handle Graphics version 2</i>). At the time, I was sure that HG2 was just around the corner. But three years and six releases have passed, Matlab 7 turned into Matlab 8, and HG1 is still in use. I decided that it was time to revisit the latest state of HG2, as reflected in the latest release, R2013a (Matlab 8.1).</p>
<p>In the past few years, development of HG2 has apparently progressed to a stage where most of the kinks were ironed out. The latest HG2 appears to be quite stable, and in my experience most GUI/graphics utilities run as-is, without any need for tweaking. This is good news, which leads me to think that HG2 will be released soon. It is possible that this could happen as early as the upcoming release (R2013b, 8.2) but I have a gut feeling that it will be in R2014a. I also have a gut feeling that MathWorks will name that release 9.0 rather than 8.3, in keeping with its arch-rival <a target="_blank" rel="nofollow" href="http://www.wolfram.com/mathematica/">Mathematica</a>.</p>
<p>HG2 has improved grid lines, plot anti-aliasing and customizable everything (more on this below). Here&#8217;s a simple plot line as it appears in both HG1 and HG2:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hFig = <span style="color: #0000FF;">figure</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">100</span>,<span style="color: #33f;">100</span>,<span style="color: #33f;">300</span>,<span style="color: #33f;">250</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
x = -<span style="color: #33f;">10</span><span style="color: #F0F;">:</span><span style="color: #33f;">0.1</span><span style="color: #F0F;">:</span><span style="color: #33f;">10</span>;
y = 1e7*<span style="color: #0000FF;">sin</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>./x; 
hLine = <span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>x,y<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">box</span> off; <span style="color: #0000FF;">grid</span> on;
<span style="color: #0000FF;">title</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'HG2 plot'</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 630px"><img alt="HG1 plot" src="http://UndocumentedMatlab.com/images/HG1_plot.png" title="HG1 plot" width="300" height="325" /><img alt="HG2 plot" src="http://UndocumentedMatlab.com/images/HG2_plot.png" title="HG2 plot" width="300" height="325" /><p class="wp-caption-text">Same plot in HG1 and HG2</p></div></center></p>
<p>We can see that MathWorks has invested heavily in improving usability. The graphics are now much more visually appealing than before. A lot of thought has gone into small details such as the plot colors and the axes gray shades. The changes are small when taken separately, but the overall gestalt is striking. HG2 will definitely justify my license maintenance cost.<br />
<span id="more-3789"></span></p>
<h3 id="customizable">Highly customizable</h3>
<p>Matlab in HG2 mode acts and behaves pretty much as you would expect. There are no visible changes to the Desktop or the graphics interface. The major difference is that all graphics handles, whether interactive controls (figure, uicontrols, uitables, etc.) or graph elements (axes, lines, patches, etc.) are instances of class objects (e.g., <code>matlab.ui.Figure</code> or <code>matlab.graphics.chart.primitive.Line</code>) rather than numeric values. This makes it easy to issue commands such as:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hFig.<span style="">Color</span> = <span style="color:#A020F0;">'w'</span>;
&nbsp;
hAxes.<span style="color: #0000FF;">Title</span>.<span style="">Color</span> = <span style="color:#A020F0;">'m'</span>;  <span style="color: #228B22;">% default: [0,0,0] = black</span>
hAxes.<span style="">YRuler</span>.<span style="">SecondaryLabel</span>.<span style="">String</span> = <span style="color:#A020F0;">'millions'</span>;  <span style="color: #228B22;">% original: 'x10^{6}'</span>
hAxes.<span style="">YRuler</span>.<span style="">SecondaryLabel</span>.<span style="">FontAngle</span> = <span style="color:#A020F0;">'italic'</span>;  <span style="color: #228B22;">% default: 'normal'</span>
hAxes.<span style="">YRuler</span>.<span style="">Axle</span>.<span style="">LineStyle</span> = <span style="color:#A020F0;">'dotted'</span>;  <span style="color: #228B22;">% default: 'solid'</span>
hAxes.<span style="">YRuler</span>.<span style="">Axle</span>.<span style="">ColorData</span> = <span style="color: #0000FF;">uint8</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">0</span>,<span style="color: #33f;">100</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">255</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>';  <span style="color: #228B22;">%=dark green; default: [51 51 51 255], corresponding to [0.2 0.2 0.2 1]</span>
hAxes.<span style="">YBaseline</span>.<span style="">Color</span> = <span style="color:#A020F0;">'b'</span>;  <span style="color: #228B22;">% default: [0.2 0.2 0.2]</span>
hAxes.<span style="">YBaseline</span>.<span style="">Visible</span> = <span style="color:#A020F0;">'on'</span>;  <span style="color: #228B22;">% default: 'off'</span>
hAxes.<span style="">XRuler</span>.<span style="">Axle</span>.<span style="">Visible</span> = <span style="color:#A020F0;">'off'</span>;  <span style="color: #228B22;">% default: 'on'</span>
&nbsp;
hLine.<span style="">Color</span> = <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">0</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>;  <span style="color: #228B22;">%='red'</span></pre></div></div>

<p>rather than using the corresponding <i><b>set(&#8230;)</b></i> or <i><b>get(&#8230;)</b></i> functions, which are still supported for backward compatibility. </p>
<p><center><div class="wp-caption aligncenter" style="width: 326px"><img alt="Customized HG2 plot" src="http://UndocumentedMatlab.com/images/HG2_plot2.png" title="Customized HG2 plot" width="316" height="342" /><p class="wp-caption-text">Customized HG2 plot</p></div></center></p>
<p>Notice how much more customizable HG2 is compared to HG1. I am pretty excited from the huge number of additional possible customizations in HG2 compared to HG1. It is real a pity that many of these customizations rely on hidden/undocumented properties (see below). Hopefully this will change when HG2 is officially released.</p>
<h3 id="observations">Some observations</h3>
<p>Here are a few observations that I collected on the latest HG2, as reflected in R2013a:</p>
<ol>
<li>Java is still supported (hurray!). The warnings about the figure&#8217;s <a target="_blank" href="http://undocumentedmatlab.com/blog/disable-entire-figure-window/#JavaFrame"><b>JavaFrame</b> property</a> becoming deprecated have fortunately not been fulfilled (hopefully never). All the Java-based GUI tricks shown on this blog and in my book still work, excluding some minor things here and there which are due to inter-release changes rather than to the new HG2 engine.</li>
<li>In order to access the top-level Java <code>Frame</code> of a figure window, we now need to use <code>javaFrame.fHG2Client</code> rather than <a target="_blank" href="http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/"><code>javaFrame.fHG1Client</code></a>. The relevant code should now look something like this, in order to be fully-compatible with older Matlab releases:

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>hFig<span style="color: #080;">&#41;</span>, <span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">try</span>
    <span style="color: #228B22;">% This works up to R2011a</span>
    jFrame.<span style="">fFigureClient</span>.<span style="">setClientDockable</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">catch</span>
    <span style="color: #0000FF;">try</span>
        <span style="color: #228B22;">% This works from R2008b and up, up to HG2</span>
        jFrame.<span style="">fHG1Client</span>.<span style="">setClientDockable</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">catch</span>
        <span style="color: #228B22;">% This works in HG2</span>
        jFrame.<span style="">fHG2Client</span>.<span style="">setClientDockable</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div>

</li>
<li>Anti-aliasing of plot elements (a.k.a. line -smoothing) is now &#8216;on&#8217; by default (double hurray!). Apparently, MathWorks solved the problems with the existing <a target="_blank" href="http://undocumentedmatlab.com/blog/plot-linesmoothing-property/">undocumented <b>LineSmoothing</b> property</a>. Still, for some unknown reason, <b>LineSmoothing</b> remains a hidden/undocumented property. Note that for some objects the property name is different. For example, the axes title (which is a <i><b>text</b></i> object of class <code>matlab.graphics.primitive.Text</code>) has a new property called <b>Smoothing</b> that controls anti-aliasing (unlike <b>LineSmoothing</b>, <b>Smoothing</b> appears to be an un-hidden fully-documented property).
</li>
<li>Many new properties have been added to graphic objects, that enable customization of different aspects. For example, we can customize the axes grid-lines, containing box and exponent labels in ways that were impossible in HG1 (triple hurray!). Note that many of these new properties are hidden/undocumented (why the hell for???), so we need a utility such as my <a target="_blank" href="http://undocumentedmatlab.com/blog/uiinspect/"><i><b>uiinspect</b></i></a> or <a target="_blank" rel="nofollow" href="http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/"><i><b>getundoc</b></i></a> to detect them. Some of the useful new axes properties include <b>*Ruler, *Baseline, *GridHandle, BoxFrame</b> and <b>BackDrop</b> (I showed an example usage of <b>*Ruler</b> and <b>*Baseline</b> above). I have absolutely no idea why these so-useful properties are kept hidden, it simply makes no sense.</li>
<li>Some existing HG1 properties are missing. For example, the <b>UserData</b> property is no longer available for some Java objects (this is a real pity &#8212; I depended on it for many functionalities, such as storing node-specific data in <i><b>uitree</b></i>/<code>JTree</code> nodes). Similarly, axes no longer have <a target="_blank" href="http://undocumentedmatlab.com/blog/plot-liminclude-properties/"><b>*LimInclude</b> properties</a> (this actually makes sense &#8211; these properties are still available in plot lines, where they actually have a use).</li>
<li>Some existing HG1 properties now issue a warning, although they still work. For example:

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; hAxes.<span style="">DrawMode</span> = <span style="color:#A020F0;">'fast'</span>;
<span style="color: #0000FF;">Warning</span><span style="color: #F0F;">:</span> The DrawMode property will be removed in a future release.
<span style="color: #080;">&#40;</span><span style="color: #0000FF;">Type</span> &quot;warning off MATLAB<span style="color: #F0F;">:</span>hg<span style="color: #F0F;">:</span>willberemoved&quot; to suppress this <span style="color: #0000FF;">warning</span>.<span style="color: #080;">&#41;</span> 
&nbsp;
&gt;&gt; hLine.<span style="">LineSmoothing</span>
<span style="color: #0000FF;">Warning</span><span style="color: #F0F;">:</span> The LineSmoothing property will be removed in a future release.
<span style="color: #080;">&#40;</span><span style="color: #0000FF;">Type</span> &quot;warning off MATLAB<span style="color: #F0F;">:</span>hg<span style="color: #F0F;">:</span>willberemoved&quot; to suppress this <span style="color: #0000FF;">warning</span>.<span style="color: #080;">&#41;</span> 
<span style="color: #0000FF;">ans</span> =
on</pre></div></div>

</li>
<li>There is an open bug on R2012b and R2013a whereby the <i><b>clf</b></i> function does not delete <a target="_blank" href="http://undocumentedmatlab.com/blog/javacomponent/"><i><b>javacomponent</b></i></a> objects. This bug does not affect HG2, where <i><b>clf</b></i> works properly.</li>
<li>Some GUI components are being placed a pixel or two sideways in HG2 compared to HG1. This has no visual importance except in very rare cases, but it does affect my <a target="_blank" href="http://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object/"><i><b>findjobj</b></i> utility</a>, which relies on the component&#8217;s position to find its underlying Java object.</li>
<li>The default axes and labels color has changed from black to gray ([0.2 0.2 0.2]). Grid lines now use an even lighter gray shade. Visually I think that this is a great change, since it focuses the viewer&#8217;s focus on the plot contents rather than the external decorations.
</li>
<li>The default axes plot color order has changed. The standard plot color is no longer blue (as it was for ages in Matlab), but a bluish tint; the second color is no longer red but light green; the third color is reddish rather than dark green, etc.:

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% HG1</span>
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'defaultAxesColorOrder'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
            <span style="color: #33f;">0</span>            <span style="color: #33f;">0</span>            <span style="color: #33f;">1</span>
            <span style="color: #33f;">0</span>          <span style="color: #33f;">0.5</span>            <span style="color: #33f;">0</span>
            <span style="color: #33f;">1</span>            <span style="color: #33f;">0</span>            <span style="color: #33f;">0</span>
            <span style="color: #33f;">0</span>         <span style="color: #33f;">0.75</span>         <span style="color: #33f;">0.75</span>
         <span style="color: #33f;">0.75</span>            <span style="color: #33f;">0</span>         <span style="color: #33f;">0.75</span>
         <span style="color: #33f;">0.75</span>         <span style="color: #33f;">0.75</span>            <span style="color: #33f;">0</span>
         <span style="color: #33f;">0.25</span>         <span style="color: #33f;">0.25</span>         <span style="color: #33f;">0.25</span>
&nbsp;
<span style="color: #228B22;">%HG2</span>
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'defaultAxesColorOrder'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
     <span style="color: #33f;">0.070588</span>      <span style="color: #33f;">0.40784</span>      <span style="color: #33f;">0.70196</span>
      <span style="color: #33f;">0.92941</span>      <span style="color: #33f;">0.14118</span>      <span style="color: #33f;">0.14902</span>
      <span style="color: #33f;">0.60784</span>       <span style="color: #33f;">0.7451</span>      <span style="color: #33f;">0.23922</span>
      <span style="color: #33f;">0.48235</span>      <span style="color: #33f;">0.17647</span>       <span style="color: #33f;">0.4549</span>
            <span style="color: #33f;">1</span>      <span style="color: #33f;">0.78039</span>            <span style="color: #33f;">0</span>
      <span style="color: #33f;">0.30196</span>       <span style="color: #33f;">0.7451</span>      <span style="color: #33f;">0.93333</span>
      <span style="color: #33f;">0.82353</span>       <span style="color: #33f;">0.4549</span>            <span style="color: #33f;">0</span></pre></div></div>

</li>
<li>HG2 axes no longer forget the previous plot color (unless we used <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/loren/2009/06/03/hold-everything/"><i><b>hold all</b></i></a>) &#8212; in HG2 color cycling is on by default. Note that this causes some visual discrepancies between HG1 and HG2 in plots that use <i><b>hold on</b></i> and have multiple plot lines: In HG1 they were all blue; in HG2 the first is bluish, the second is greenish, then reddish etc.</li>
<li>GUIDE is still the same-ol&#8217; GUIDE (sigh!). The figure toolbar and menubar have likewise not been upgraded, as far as I could tell.</li>
<li>HG2 performance appears to be generally slower than HG1. Hopefully this will improve by the time HG2 is released, since performance has been one of HG1&#8242;s drawbacks all along. In my tests, most GUI/graphic aspects ran only slightly slower in HG2, except for 2D plots that were significantly slower. This is corroborated by running <i><b>bench</b></i>: on my computer, HG1 yields 0.4 for 2D and 0.22 for 3D; in HG2 the performance is 2.1 for 2D and 0.18 for 3D. Looks like the 2D performance still needs some work&#8230;</li>
</ol>
<h3 id="testing">Testing HG2</h3>
<p>As noted in my <a target="_blank" href="http://undocumentedmatlab.com/blog/matlab-hg2/">original article</a>, we can start Matlab in HG2 mode by simply adding the startup (command-line) switch <i>-hgVersion 2</i> to the Matlab command (note the space between the <code>-hgVersion</code> and the &#8220;2&#8243;). For example, in Windows, all you need to do is to copy your Matlab shortcut sideways (so that you will always have the standard HG1 version available), then right-click the shortcut, select &#8220;Properties&#8221;, then add <i>-hgVersion 2</i> to the Target field. You will probably want to also add the &#8220;HG2&#8243; descriptor to the shortcut name, in the &#8220;General&#8221; tab:</p>
<p><center><div class="wp-caption aligncenter" style="width: 387px"><img alt="Matlab startup switch for HG2" src="http://UndocumentedMatlab.com/images/HG2_shortcut_props.png" title="Matlab startup switch for HG2" width="377" height="428" /><p class="wp-caption-text">Matlab startup switch for HG2</p></div></center></p>
<p>If you have any Matlab application that relies on GUI or graphics, I urge you to test it on the new HG2 system. It&#8217;s trivially simple and your application should work exactly the same, or better. If you do detect some incompatibility, please <a href="http://undocumentedmatlab.com/blog/hg2-update/#respond">post a comment</a> or <a href="mailto: altmany @gmail.com?subject=HG2 feedback&amp;body=Hi Yair, &amp;cc=;&amp;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=HG2 feedback&amp;body=Hi Yair, '); return false;">shoot me an email</a>. In due course I expect that MathWorks will open an official channel for this, but in the meantime I&#8217;ll be sure to pass the information to the relevant person. </p>
<p>Do take a moment for testing HG2 &#8211; we can all contribute to ensure that when HG2 does come out it will be perfect. It&#8217;s in our interest.</p>
<h3 id="NYC_visit">NYC visit</h3>
<p>If you happen to be in New York next week, I urge you to attend the MATLAB Computational Conference on Thursday May 23 (free <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/events/conferences/matlab-computational-finance-conference-nyc/2013/registration.html">registration</a>; my presentation is scheduled for 4:50pm). I would be happy to meet you to discuss how I could bring value to your needs, either financial-oriented or not. We could meet at the conference, or anywhere in New York on Wednesday May 22 or Friday May 24.</p>
<p><center><a href="http://undocumentedmatlab.com/blog/nyc-visit-may-2013/"><img title="Matlab Computational Finance Conference - 23 May 2013" src="http://undocumentedmatlab.com/images/conference_invite_animated.gif" alt="Matlab Computational Finance Conference - 23 May 2013" width="324" height="86"/></a></center></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/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/panel-level-uicontrols/' rel='bookmark' title='Panel-level uicontrols'>Panel-level uicontrols</a> <small>Matlab's uipanel contains a hidden handle to the title label, which can be modified into a checkbox or radio-button control...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/multi-column-grid-legend/' rel='bookmark' title='Multi-column (grid) legend'>Multi-column (grid) legend</a> <small>This article explains how to use undocumented axes listeners for implementing multi-column plot legends...</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=tIztzUrEpNA:_g--VjveqZc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=tIztzUrEpNA:_g--VjveqZc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=tIztzUrEpNA:_g--VjveqZc:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=tIztzUrEpNA:_g--VjveqZc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=tIztzUrEpNA:_g--VjveqZc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=tIztzUrEpNA:_g--VjveqZc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=tIztzUrEpNA:_g--VjveqZc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=tIztzUrEpNA:_g--VjveqZc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=tIztzUrEpNA:_g--VjveqZc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=tIztzUrEpNA:_g--VjveqZc:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/tIztzUrEpNA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/hg2-update/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/hg2-update/</feedburner:origLink></item>
		<item>
		<title>Improving save performance</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/tLlT_eeP9Eo/</link>
		<comments>http://undocumentedmatlab.com/blog/improving-save-performance/#comments</comments>
		<pubDate>Wed, 08 May 2013 19:37:50 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pure Matlab]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3762</guid>
		<description><![CDATA[There are many different ways of improving Matlab's standard save function performance.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/improving-fwrite-performance/' rel='bookmark' title='Improving fwrite performance'>Improving fwrite performance</a> <small>Standard file writing performance can be improved in Matlab in surprising ways. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/mlintfailurefiles/' rel='bookmark' title='MLintFailureFiles or: Why can&#8217;t I save my m-file?!'>MLintFailureFiles or: Why can&#8217;t I save my m-file?!</a> <small>Sometimes Matlab gets into a state where it cannot use a valid m-file. This article explains what can be done. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/datestr-performance/' rel='bookmark' title='datestr performance'>datestr performance</a> <small>Caching is a simple and very effective means to improve code performance, as demonstrated for the datestr function....</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>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Two weeks ago I posted an article about <a target="_blank" href="http://undocumentedmatlab.com/blog/improving-fwrite-performance/">improving <i><b>fwrite</b></i>&#8216;s performance</a>. <i><b>fwrite</b></i> is normally used to store binary data in some custom pre-defined format. But we often don&#8217;t need or want to use such low-level functions. Matlab&#8217;s built-in <i><b>save</b></i> function is an easy and very convenient way to store data in both binary and text formats. This data can later be loaded back into Matlab using the <i><b>load</b></i> function. Today&#8217;s article will show little-known tricks of improving <i><b>save</b></i>&#8216;s performance.</p>
<p>MAT is Matlab’s default data format for the <i><b>save</b></i> function. This format is <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/pdf_doc/matlab/matfile_format.pdf">publicly available</a> and adaptors are available for other programming languages (<a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/fileexchange/26731-portable-matfile-exporter-in-c">C</a>, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/16319-csmatio-mat-file-io-api-for-net-2-0">C#</a>, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/10759-jmatio-matlabs-mat-file-io-in-java">Java</a>). Matlab 6 and earlier did not employ automatic data compression; Matlab versions 7.0 (R14) through 7.2 (R2006a) use GZIP compression; Matlab 7.3 (R2006b) and newer can use an HDF5-variant format, which apparently <a target="_blank" rel="nofollow" href="http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/matlab/HDF5_M_Examples/h5ex_d_gzip.m">also uses GZIP</a> (level-3) compression, although MathWorks might have done better to pay the license cost of employing <a target="_blank" rel="nofollow" href="http://www.hdfgroup.org/doc_resource/SZIP/">SZIP</a> (<i>thanks to Malcolm Lidierth for the clarification</i>). Note that Matlab’s 7.3 format is <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/answers/15521#answer_23983">not a pure HDF5 file</a>, but rather a HDF5 variant that uses an undocumented internal format.</p>
<p>The following table summarizes the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/save.html#inputarg_version">available options</a> for saving data using the save function: </p>
<table border="0">
<thead>
<tr>
<th><i><b>save</b></i> option</th>
<th>Available since</th>
<th>Data format</th>
<th>Compression</th>
<th>Major functionality</th>
</tr>
</thead>
<tr>
<td><code>-v7.3</code></td>
<td>R2006b (7.3)</td>
<td>Binary (HDF5)</td>
<td>GZIP</td>
<td>2GB files, class objects</td>
</tr>
<tr>
<td><code>-v7</code></td>
<td>R14 (7.0)</td>
<td>Binary (MAT)</td>
<td>GZIP</td>
<td>Compression, Unicode</td>
</tr>
<tr>
<td><code>-v6</code></td>
<td>R8 (5.0)</td>
<td>Binary (MAT)</td>
<td>None</td>
<td>N-D arrays, cell arrays, structs</td>
</tr>
<tr>
<td><code>-v4</code></td>
<td>All releases</td>
<td>Binary (MAT)</td>
<td>None</td>
<td>2D data</td>
</tr>
<tr>
<td><code>-ascii</code></td>
<td>All releases</td>
<td>Text</td>
<td>None</td>
<td>Tab/space delimited</td>
</tr>
</table>
<p>HDF5 uses a generic format to store data of any conceivable type, and has a non-significant storage overhead in order to describe the file&#8217;s contents. Moreover, Matlab’s HDF5 implementation <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/255244#663437">does not by default compress non-numeric data</a> (struct and cell arrays). For this reason, HDF5 files are typically larger and slower than non-HDF5 MAT files, especially if the data contains cell arrays or structs. This holds true for both pure-HDF files (saved via the <i><b>hdf</b></i> and <i><b>hdf5</b></i> set of functions, for HDF4 and HDF5 formats respectively), and v7.3-format MAT files.</p>
<p>Perhaps for this reason the default preference is for save to use –v7, even on new releases that support –v7.3. This preference can be changed in Matlab&#8217;s Preferences/General window (or we could always specify the –v7/-v7.3 switch directly when using <i><b>save</b></i>):</p>
<p><center><div class="wp-caption aligncenter" style="width: 627px"><img alt="Matlab's preferences for saving binary data" src="http://UndocumentedMatlab.com/images/Preferences_MAT.png" title="Matlab's preferences for saving binary data" width="617" height="320" /><p class="wp-caption-text">Matlab's preferences for saving binary data</p></div></center><br />
<span id="more-3762"></span></p>
<p>Over the years, MathWorks has fixed several inefficiencies when reading HDF5 files (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/support/bugreports/938249">ref1</a>, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/support/bugreports/736830">ref2</a>). Some of these fixes include patches for older releases, and readers are advised to download and install the appropriate patches if you do not use the latest Matlab release (currently R2013a). There are still a couple of open bugs regarding HDF5 <a target="_blank" rel="nofollow" href="http://www.mathworks.com/support/bugreports/331250">performance</a> and <a target="_blank" rel="nofollow" href="http://www.mathworks.com/support/bugreports/784028">compression</a> that may affect <i><b>save</b></i>.</p>
<p>One might think that due to the generic descriptive file header and the increased I/O, as well as the open bug, the -v7.3 (HDF5) format would always be slower than –v7 (MAT) format in <i><b>save</b></i> and <i><b>load</b></i>. This is indeed often the case, but not always:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">A = randi<span style="color: #080;">&#40;</span><span style="color: #33f;">20</span>,<span style="color: #33f;">1000</span>,<span style="color: #33f;">1200</span>,<span style="color: #33f;">40</span>,<span style="color:#A020F0;">'int32'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% 48M int32s =&gt; 184 MB</span>
B = <span style="color: #0000FF;">randn</span><span style="color: #080;">&#40;</span><span style="color: #33f;">500</span>,<span style="color: #33f;">1000</span>,<span style="color: #33f;">20</span><span style="color: #080;">&#41;</span>;              <span style="color: #228B22;">% 80M doubles =&gt; 78 MB</span>
ops.<span style="">algo</span> = <span style="color:#A020F0;">'test'</span>;                   <span style="color: #228B22;">% non-numeric</span>
&nbsp;
<span style="color: #0000FF;">tic</span>, <span style="color: #0000FF;">save</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'test1.mat'</span>,<span style="color:#A020F0;">'-v7'</span>,<span style="color:#A020F0;">'ops'</span>,<span style="color:#A020F0;">'A'</span>,<span style="color:#A020F0;">'B'</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
<span style="color: #228B22;">% =&gt; Elapsed time is 11.940455 seconds.   % file size: 114 MB</span>
&nbsp;
<span style="color: #0000FF;">tic</span>, <span style="color: #0000FF;">save</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'test2.mat'</span>,<span style="color:#A020F0;">'-v7.3'</span>,<span style="color:#A020F0;">'ops'</span>,<span style="color:#A020F0;">'A'</span>,<span style="color:#A020F0;">'B'</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
<span style="color: #228B22;">% =&gt; Elapsed time is 6.963135 seconds.    % file size: 116 MB</span></pre></div></div>

<p>In this case, the HDF5 format was much faster than MAT, offsetting the benefits of the MAT’s reduced I/O. This example shows that we need to check our specific application’s data files on a case-by-case basis. For some files –v7 may be better; for others –v7.3 is best. The <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/255244#663448">widely-accepted conventional wisdom</a> of only using the new –v7.3 format for enormous (>2GB) files  is inappropriate. In general, if the data contains many non-numeric elements, the resulting –v7.3 HDF5 file is much <a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/4950630/matlab-differences-between-mat-versions">larger and slower</a> than the –v7 MAT file, while if the data is mostly numeric, then –v7.3 would be faster and comparable in size.</p>
<p>Surprisingly, we can often sacrifice compression to (paradoxically) achieve better performance, for both save and load, at the expense of much larger file size. This is done by saving the numeric data in uncompressed HDF5 format, using the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/39721-save-mat-files-more-quickly"><i><b>savefast</b></i> utility</a> on the Matlab File Exchange, using the same syntax as <i><b>save</b></i>:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">tic</span>, savefast<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'test3.mat'</span>,<span style="color:#A020F0;">'ops'</span>,<span style="color:#A020F0;">'A'</span>,<span style="color:#A020F0;">'B'</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
<span style="color: #228B22;">% =&gt; Elapsed time is 3.164903 seconds.   % file size: 259 MB</span></pre></div></div>

<p>Even better performance, and similar or somewhat lower file size, can be achieved by using <i><b>save</b></i>’s uncompressed format –v6. The –v6 format is <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/answers/15521">consistently faster</a> than both –v7 and –v7.3, at the expense of a larger file size. However, <i><b>save</b></i> –v6 cannot save Unicode and class objects, and is limited to &lt;2GB file sizes.</p>
<p>Another lesson here is that depending on the relative size of the numeric and non-numeric data being saved, different data format may be advisable. As the application evolves and the saved data’s size and mixture change, we might need to revisit the format decision. Here is a summary on one specific computer, using the numeric variable A (184 MB) above, together with a cell-array of varying size:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">B = <span style="color: #0000FF;">num2cell</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">randn</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,dataSize<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% dataSize = 1e3, 1e4, 1e5, 1e6</span></pre></div></div>

<table border="0">
<thead>
<tr>
<th>Numeric data</th>
<th>Non-numeric data</th>
<th><i><b>save</b></i> -v7.3</th>
<th><i><b>save</b></i> -v7</th>
<th><i><b>save</b></i> -v6</th>
<th><i><b>savefast</b></i></th>
</tr>
</thead>
<tr>
<td>184 MB</td>
<td>0.114 MB</td>
<td>3.8 secs, 43 MB</td>
<td>9.3 secs, 40 MB</td>
<td>1.6 secs, 183 MB</td>
<td>2.1 secs, 183 MB</td>
</tr>
<tr>
<td>184 MB</td>
<td>1.14 MB</td>
<td>4.3 secs, 46 MB</td>
<td>9.5 secs, 40 MB</td>
<td>1.6 secs, 184 MB</td>
<td>2.1 secs, 186 MB</td>
</tr>
<tr>
<td>184 MB</td>
<td>11.4 MB</td>
<td>12.6 secs, 78 MB</td>
<td>9.9 secs, 41 MB</td>
<td>2.7 secs, 189 MB</td>
<td>11.1 secs, 219 MB</td>
</tr>
<tr>
<td>184 MB</td>
<td>114 MB</td>
<td>87.5 secs, 402 MB</td>
<td>13.9 secs, 50 MB</td>
<td>5.8 secs, 244 MB</td>
<td>85.2 secs, 544 MB</td>
</tr>
</table>
<p>As noted, and as can be clearly seen in the table, compression is not enabled for non-numeric data in the <i><b>save</b></i> –v7.3 (HDF5) option and <i><b>savefast</b></i>. However, we can implement our own <i><b>save</b></i> variant that does compress, by using low-level HDF5 primitives in <a target="_blank" rel="nofollow" href="http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/api18-m.html">m-code</a> or mex <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/268923">c-code</a>.</p>
<p>A general conclusion that can be drawn from all this is that in the specific case of <i><b>save</b></i>, the additional time for compression is often NOT offset by the reduced I/O. So the general rule is to <u><b>use –v6 whenever possible</b></u>.</p>
<p>Although <i><b>save</b></i> –v6 does not compress its data, it does store data in a more compact manner than Matlab memory. So, while our test set’s cell array held 114 MB of Matlab memory, on disk it was only stored within 55 MB (= 244 MB – 189 MB). </p>
<p>The performance of saving non-numeric data can be dramatically improved (and the file size reduced correspondingly) by manually serializing the data into a series of <i><b>uint8</b></i> bytes that can easily be saved very compactly. When loading the files, we would simply deserialize the loaded data. I recommend using Christian Kothe’s excellent <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/fileexchange/34564-fast-serialize-deserialize"><i>Fast serialize/deserialize</i> utility</a> on Matlab’s File Exchange. The huge gain in performance and file size when using serialized data is absolutely amazing (esp. for data types that -v6 cannot save), for all the <i><b>save</b></i> alternatives:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">B = <span style="color: #0000FF;">num2cell</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">randn</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,1e6<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% 1M cell array, 114 MB in Matlab memory</span>
B_ser = hlp_serialize<span style="color: #080;">&#40;</span>B<span style="color: #080;">&#41;</span>;</pre></div></div>

<table border="0">
<thead>
<tr>
<th>Saved variable</th>
<th>Matlab memory</th>
<th><i><b>save</b></i> -v7.3</th>
<th><i><b>save</b></i> -v7</th>
<th><i><b>save</b></i> -v6</th>
<th><i><b>savefast</b></i></th>
</tr>
</thead>
<tr>
<td>B</td>
<td>114 MB</td>
<td>83 secs, 361 MB</td>
<td>4.5 secs, 9.2 MB</td>
<td>3.5 secs, 61 MB</td>
<td>83 secs, 361 MB</td>
</tr>
<tr>
<td>B_ser</td>
<td>7.6 MB</td>
<td>1.21 secs, 7.4 MB</td>
<td>1.17 secs, 7.4 MB</td>
<td>0.93 secs, 7.6 MB</td>
<td>0.94 secs, 7.6 MB</td>
</tr>
</table>
<p>Serializing data in this manner enables <i><b>save</b></i> –v6 to be used even for Unicode and class objects (that would otherwise require –v7), as well as huge data (that would otherwise require &gt;2GB files, and usage of –v7.3). One user has <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/299353#830958">reported</a> that the run-time for saving a 2.5GB cell-array of structs was reduced from hours to a single minute using serialization (despite the fact that he was using a <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/fileexchange/29457-serialize-deserialize">non-optimized serialization</a>, not Christian’s faster utility). In addition to the performance benefits, saving class objects in this manner avoids a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/support/bugreports/857319">memory leak bug</a> that occurs when saving objects to MAT files on Matlab releases R2011b-R2012b (7.13-8.0). </p>
<p>When the data is purely numeric, we could use <i><b>hdf5write</b></i> or <i><b>h5create</b></i> + <i><b>h5write</b></i>, in addition to <i><b>save</b></i> and <i><b>savefast</b></i> (see <a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/4814569/what-is-the-fastest-way-to-load-data-in-matlab">related</a>). Note that <i><b>hdf5write</b></i> will be phased out in a future Matlab release; MathWorks advises to use <i><b>h5create</b></i> + <i><b>h5write</b></i> instead. Here are the corresponding results for 184 MB of numeric data on a standard 5400 RPM hard disk and an SSD: </p>
<table border="0">
<thead>
<tr>
<th></th>
<th><i><b>hdfwrite</b></i></th>
<th><i><b>h5create</b></i> + <i><b>h5write</b></i> (Deflate=0)</th>
<th><i><b>h5create</b></i> + <i><b>h5write</b></i> (Deflate=1)</th>
<th><i><b>save</b></i> -v7.3</th>
<th><i><b>save</b></i> -v7</th>
<th><i><b>save</b></i> -v6</th>
<th><i><b>savefast</b></i></th>
</tr>
</thead>
<tr>
<td>File size</td>
<td>183 MB</td>
<td>366 MB</td>
<td>55 MB</td>
<td>42 MB</td>
<td>40 MB</td>
<td>183 MB</td>
<td>183 MB</td>
</tr>
<tr>
<td>Time (hard disk)</td>
<td>4.4 secs</td>
<td>14.3 secs</td>
<td>7.4 secs</td>
<td>6.1 secs</td>
<td>10.8 secs</td>
<td>4.2 secs</td>
<td>4.3 secs</td>
</tr>
<tr>
<td>Time (SSD)</td>
<td>2.1 secs</td>
<td>0.2 secs</td>
<td>4.5 secs</td>
<td>4.1 secs</td>
<td>9.5 secs</td>
<td>1.5 secs</td>
<td>1.6 secs</td>
</tr>
</table>
<p>As noted, Matlab’s HDF5 implementation is generally suboptimal. Better performance <a target="_blank" rel="nofollow" href="http://www.mathworks.com/support/bugreports/331250">can be achieved</a> by using the low-level HDF5 functions, rather than the high-level hdfwrite, hdf5read functions.  </p>
<p>In addition to HDF5, Matlab also supports the HDF4 standard, using a separate set of built-in <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/hdf.html"><i><b>hdf</b></i></a> functions. Despite their common name and origin, HDF4 and HDF5 are incompatible; use different data formats; and employ different designs, APIs and Matlab access functions. HDF4 is generally much <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/129639">slower than HDF5</a>. </p>
<p>While <i><b>save</b></i>’s –v7.3 format is significantly slower than the alternatives for storing entire data elements, one specific case in which –v7.3 should indeed be considered is when we need to update or load just a small part of the data, on R2011b or newer. This could <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/release-notes.html#bs10ply-2">potentially</a> save a lot of I/O, especially for large MAT files where only a small part is updated or loaded. </p>
<p><center><a href="http://undocumentedmatlab.com/blog/nyc-visit-may-2013/"><img title="Matlab Computational Finance Conference - 23 May 2013" src="http://undocumentedmatlab.com/images/conference_invite_animated.gif" alt="Matlab Computational Finance Conference - 23 May 2013" width="324" height="86"/></a></center></p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/improving-fwrite-performance/' rel='bookmark' title='Improving fwrite performance'>Improving fwrite performance</a> <small>Standard file writing performance can be improved in Matlab in surprising ways. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/mlintfailurefiles/' rel='bookmark' title='MLintFailureFiles or: Why can&#8217;t I save my m-file?!'>MLintFailureFiles or: Why can&#8217;t I save my m-file?!</a> <small>Sometimes Matlab gets into a state where it cannot use a valid m-file. This article explains what can be done. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/datestr-performance/' rel='bookmark' title='datestr performance'>datestr performance</a> <small>Caching is a simple and very effective means to improve code performance, as demonstrated for the datestr function....</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>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=tLlT_eeP9Eo:7BnblyV_4Lk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=tLlT_eeP9Eo:7BnblyV_4Lk:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=tLlT_eeP9Eo:7BnblyV_4Lk:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=tLlT_eeP9Eo:7BnblyV_4Lk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=tLlT_eeP9Eo:7BnblyV_4Lk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=tLlT_eeP9Eo:7BnblyV_4Lk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=tLlT_eeP9Eo:7BnblyV_4Lk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=tLlT_eeP9Eo:7BnblyV_4Lk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=tLlT_eeP9Eo:7BnblyV_4Lk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=tLlT_eeP9Eo:7BnblyV_4Lk:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/tLlT_eeP9Eo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/improving-save-performance/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/improving-save-performance/</feedburner:origLink></item>
		<item>
		<title>New York City visit, 21-24 May 2013</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/qXsW2X1Lm0A/</link>
		<comments>http://undocumentedmatlab.com/blog/nyc-visit-may-2013/#comments</comments>
		<pubDate>Wed, 01 May 2013 08:50:20 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3748</guid>
		<description><![CDATA[I will be visiting New York 21-24 May 2013 to speak at the Matlab Computational Finance Conference.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/2012-perspective/' rel='bookmark' title='2012 perspective &amp; plans for 2013'>2012 perspective &#038; plans for 2013</a> <small>2012 has seen a continued steady growth in website content and readership. This post takes an overview of past achievements and future plans. ...</small></li>
<li><a href='http://undocumentedmatlab.com/consulting/' rel='bookmark' title='Consulting'>Consulting</a> <small>If you have reached this page, you are probably aware by now of my reputation in the Matlab community. After over 20 years of software development in a variety of...</small></li>
<li><a href='http://undocumentedmatlab.com/ib-matlab/' rel='bookmark' title='IB-Matlab'>IB-Matlab</a> <small>IB-Matlab is a commercial application that connects Matlab with Interactive-Brokers (IB). IB-Matlab provides a Matlab wrapper interface to IB&#8217;s API Java connector. This enables quantitative traders and algo traders to...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/2010-perspective/' rel='bookmark' title='2010 perspective &amp; plans for 2011'>2010 perspective &#038; plans for 2011</a> <small>2009 and 2010 have seen steady growth in readership of this website. This post takes an overview of past achievements and future plans....</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d like to break the regular flow of weekly articles, to announce that I will visit New York City on May 21-24, to speak at the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/events/conferences/matlab-computational-finance-conference-nyc/index.html">Matlab Computational Finance Conference</a> (May 23).</p>
<p>I will be very happy to meet you and discuss how I could bring value to your needs, either financial-oriented or not. We can meet at the conference, or elsewhere in NYC on other days: Tuesday (May 21), Wednesday (May 22) or Friday (May 24). If you would like to schedule a meeting, please <a href="mailto: altmany @gmail.com?subject=NYC meeting&#038;body=Hi Yair, &#038;cc=;&#038;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=NYC meeting&#038;body=Hi Yair, '); return false;">email me</a>.</p>
<h3 id="conference">Matlab Computational Finance Conference</h3>
<p><span class="alignright"><a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/events/conferences/matlab-computational-finance-conference-nyc/index.html"><img alt="Matlab Computational Finance Conference, 23 May 2013" src="http://UndocumentedMatlab.com/images/Matlab_Comp_Finance_Conf_23-5-2013.jpg" title="Matlab Computational Finance Conference, 23 May 2013" width="324" height="86" /></a></span> The Matlab Computational Finance conference is an event that takes place more-or-less annually, in different locations. In 2012 it was held in <a target="_blank" rel="nofollow" href="https://www.mathworks.com/company/events/conferences/matlab-computational-finance-conference/index.html">London</a>; in 2011 it was <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/events/conferences/matlab-computational-finance-virtual-conference/index.html">virtual</a> (online). This year it will be held in New York City on May 23, at the <a target="_blank" rel="nofollow" href="http://www.marriott.com/hotels/travel/nycmq-new-york-marriott-marquis/">Marriott Marquis</a> hotel, located in midtown (<a target="_blank" rel="nofollow" href="https://maps.google.com/maps?q=New+York+Marriott+Marquis&#038;hnear=New+York+Marriott+Marquis,+1535+Broadway,+New+York,+10036,+United+States&#038;ll=40.75857,-73.985968&#038;spn=0.022755,0.030041&#038;z=14&#038;vpsrc=6">1535 Broadway</a>, next to Times Square).</p>
<p>The free, full-day conference showcases real-world examples of how financial organizations use Matlab to develop risk, trading, investment management, and insurance applications. Highlights include:</p>
<ul>
<li>Customer presentations from leading industry practitioners in trading, risk, valuation, portfolio analysis, insurance, and regulatory compliance</li>
<li>Master class tutorials delivered by senior MathWorks engineers to enhance your understanding of Matlab features and functionality</li>
<li>Panel discussion with senior Matlab developers</li>
<li>An opportunity to network, exchange ideas, and discuss challenges and successes with industry peers and Matlab experts</li>
<li>And naturally, my presentation, slated for 16:50 (I suggest rechecking the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/events/conferences/matlab-computational-finance-conference-nyc/2013/agenda.html">agenda</a> close to the conference, to ensure that the time-slot hasn&#8217;t changed)</li>
</ul>
<p>Here is the abstract of my presentation:</p>
<blockquote><p>
MATLAB has traditionally been used for analyzing data off-line, presenting analytic recommendations that were then acted-upon manually. However, MATLAB supports direct interface with data feeds and online brokers, as well as the ability to present sophisticated graphics and user interfaces – all in real time.</p>
<p>This presentation will demonstrate an end-to-end demo trading system in MATLAB, highlighting MATLAB’s potential as a platform of choice. Interactive Brokers will be used to demonstrate live market data feed and account/portfolio input, as well as for sending trading orders to the market. The system&#8217;s user interface (GUI) showcases MATLAB&#8217;s hidden visualization and interactivity potential, for tracking order executions and charting financial time-series in real-time. Some best-practices for improving real-time performance shall also be discussed.
</p></blockquote>
<p>If you are interested in any aspect of computational finance, you will surely find some interesting presentations at this conference. So if you&#8217;re in town, I urge you to attend (hey &#8211; it&#8217;s free and I hear there&#8217;s drinks&#8230;). You can register <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/events/conferences/matlab-computational-finance-conference-nyc/2013/registration.html">here</a>. If you can&#8217;t attend in person, you will be able to see recordings of the proceedings on the conference website some time later.</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/2012-perspective/' rel='bookmark' title='2012 perspective &amp; plans for 2013'>2012 perspective &#038; plans for 2013</a> <small>2012 has seen a continued steady growth in website content and readership. This post takes an overview of past achievements and future plans. ...</small></li>
<li><a href='http://undocumentedmatlab.com/consulting/' rel='bookmark' title='Consulting'>Consulting</a> <small>If you have reached this page, you are probably aware by now of my reputation in the Matlab community. After over 20 years of software development in a variety of...</small></li>
<li><a href='http://undocumentedmatlab.com/ib-matlab/' rel='bookmark' title='IB-Matlab'>IB-Matlab</a> <small>IB-Matlab is a commercial application that connects Matlab with Interactive-Brokers (IB). IB-Matlab provides a Matlab wrapper interface to IB&#8217;s API Java connector. This enables quantitative traders and algo traders to...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/2010-perspective/' rel='bookmark' title='2010 perspective &amp; plans for 2011'>2010 perspective &#038; plans for 2011</a> <small>2009 and 2010 have seen steady growth in readership of this website. This post takes an overview of past achievements and future plans....</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=qXsW2X1Lm0A:lOrDj213gD0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=qXsW2X1Lm0A:lOrDj213gD0:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=qXsW2X1Lm0A:lOrDj213gD0:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=qXsW2X1Lm0A:lOrDj213gD0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=qXsW2X1Lm0A:lOrDj213gD0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=qXsW2X1Lm0A:lOrDj213gD0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=qXsW2X1Lm0A:lOrDj213gD0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=qXsW2X1Lm0A:lOrDj213gD0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=qXsW2X1Lm0A:lOrDj213gD0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=qXsW2X1Lm0A:lOrDj213gD0:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/qXsW2X1Lm0A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/nyc-visit-may-2013/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/nyc-visit-may-2013/</feedburner:origLink></item>
		<item>
		<title>Improving fwrite performance</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/2sYBjZssAiY/</link>
		<comments>http://undocumentedmatlab.com/blog/improving-fwrite-performance/#comments</comments>
		<pubDate>Wed, 24 Apr 2013 18:00:47 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Semi-documented feature]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pure Matlab]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3731</guid>
		<description><![CDATA[Standard file writing performance can be improved in Matlab in surprising ways.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/improving-save-performance/' rel='bookmark' title='Improving save performance'>Improving save performance</a> <small>There are many different ways of improving Matlab's standard save function performance. ...</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/performance-scatter-vs-line/' rel='bookmark' title='Performance: scatter vs. line'>Performance: scatter vs. line</a> <small>In many circumstances, the line function can generate visually-identical plots as the scatter function, much faster...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/preallocation-performance/' rel='bookmark' title='Preallocation performance'>Preallocation performance</a> <small>Preallocation is a standard Matlab speedup technique. Still, it has several undocumented aspects. ...</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Readers of this blog are probably <a target="_blank" href="http://undocumentedmatlab.com/blog/2012-perspective/">aware by now</a> that I am currently writing my second book, <i>MATLAB Performance Tuning</i> (expected publication date: early 2014, CRC Press). During my work on this book, I encounter many surprising aspects of Matlab performance. In many cases these aspects are not <i>un</i>-documented per-se, but are certainly not well known in the Matlab community. So taking some artistic liberty coupled with some influence over this blog&#8217;s owner, I&#8217;ll mention some of these interesting discoveries here, even if they are not strictly-speaking <i>undocumented</i>.</p>
<p>Today&#8217;s post is about the well-known <i><b>fwrite</b></i> function, which is used to write binary data to file. In many cases, using <i><b>fwrite</b></i> provides the fastest alternative to saving data files (<i><b>save</b>(&#8230;,&#8217;-v6&#8242;)</i> coming a close second). This function is in fact so low-level, and is used so often, that some readers may be surprised that its default speed can be improved. Today&#8217;s article applies equally to the <i><b>fprintf</b></i> function, which is used to save data in text format.</p>
<p>Apparently, there are things to be learned even with such standard low-level functions; there&#8217;s a deep moral here I guess.<br />
<span id="more-3731"></span></p>
<h3 id="buffering">Flushing and buffering</h3>
<p>Unlike <a target="_blank" rel="nofollow" href="http://www.cplusplus.com/reference/cstdio/fopen/">C/C++&#8217;s implementation</a>, Matlab&#8217;s <i><b>fprintf</b></i> and <i><b>fwrite</b></i> automatically flush the output buffer whenever they are called, even when <code>'\n'</code> is not present in the output stream. This is not mentioned outright in the main documentation, but is stated loud and clear in the official <a target="_blank" rel="nofollow" href="http://www.mathworks.com/support/solutions/en/data/1-PV371/">technical support solution 1-PV371</a>.</p>
<p>The only exception to this rule is when the file was <i><b>fopen</b></i>&#8216;ed with the <code>'W'</code> or <code>'A'</code> specifiers (which for some inexplicable reason is NOT mentioned in the technical solution!), or when outputting to the MATLAB’s Command Window (more precisely, to STDOUT (fid=1) and STDERR (fid=2)). Writing data without buffering in this manner severely degrades I/O performance:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">data = randi<span style="color: #080;">&#40;</span><span style="color: #33f;">250</span>,1e6,<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% 1M integer values between 1-250</span>
&nbsp;
<span style="color: #228B22;">% Standard unbuffered writing - slow</span>
fid = <span style="color: #0000FF;">fopen</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'test.dat'</span>, <span style="color:#A020F0;">'wb'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">tic</span>, <span style="color: #0000FF;">for</span> idx = <span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>data<span style="color: #080;">&#41;</span>, <span style="color: #0000FF;">fwrite</span><span style="color: #080;">&#40;</span>fid,data<span style="color: #080;">&#40;</span>idx<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">end</span>, <span style="color: #0000FF;">toc</span>
<span style="color: #0000FF;">fclose</span><span style="color: #080;">&#40;</span>fid<span style="color: #080;">&#41;</span>;
  =&gt; Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">14.006194</span> seconds.
&nbsp;
<span style="color: #228B22;">% Buffered writing – x4 faster</span>
fid = <span style="color: #0000FF;">fopen</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'test.dat'</span>, <span style="color:#A020F0;">'Wb'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">tic</span>, <span style="color: #0000FF;">for</span> idx = <span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>data<span style="color: #080;">&#41;</span>, <span style="color: #0000FF;">fwrite</span><span style="color: #080;">&#40;</span>fid,data<span style="color: #080;">&#40;</span>idx<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">end</span>, <span style="color: #0000FF;">toc</span>
<span style="color: #0000FF;">fclose</span><span style="color: #080;">&#40;</span>fid<span style="color: #080;">&#41;</span>;
  =&gt; Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">3.471557</span> seconds.</pre></div></div>

<p>If I were in a generous mood, I could say that we could infer this information from <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/fopen.html#inputarg_permission"><i><b>fopen</b></i>&#8216;s doc page</a>, where it mentions using the <code>'W'</code> and <code>'A'</code> permission specifiers to <i>prevent</i> automatic flushing, although it qualifies this with the very misleading statement that these specifiers are &#8220;<i>Used with tape drives</i>&#8220;. So first of all, who ever uses tape drives with Matlab nowadays?! Secondly, these specifiers are very useful for regular buffered I/O on standard disks and other I/O interfaces. I really think this was a poor choice of words. At the very least some extra clarification about these specifiers could be added. </p>
<p>It was also (IMHO) a poor design choice by MathWorks in the first place to break consistency with the C/C++ implementation for <code>'w'</code> and associate the functionality to <code>'W'</code> (and similarly, <code>'a'</code> vs. <code>'A'</code>). C&#8217;s <i>fopen</i> was in widespread usage for a decade before Matlab was invented, so there is really no excuse, certainly when Matlab&#8217;s <i><b>fopen</b></i> was so clearly modeled after the C implementation. It would have been more reasonable (again &#8211; IMHO) to preserve consistency of <code>'w'</code> and <code>'a'</code> for a default of buffered I/O (which is faster!), while providing the non-buffered functionality in <code>'W'</code> and <code>'A'</code>.</p>
<p>The vast majority of Matlab users <i><b>fopen</b></i> their files using <code>'w'</code> and not <code>'W'</code>. Even Matlab&#8217;s own documentation always uses <code>'w'</code> and not <code>'W'</code>. So coupled with the poorly-worded qualification about the tape drives, and the unintuitive inconsistency with C&#8217;s implementation, Matlab users could well be excused for not taking advantage of this feature.</p>
<h3 id="chunking">Chunking I/O</h3>
<p>The idea of buffering, and the reason behind the speedup above, is that I/O is faster when writing full pages (typically 4KB, but this changes on different platforms) and when bunched together to remove the disk access time between adjacent writes. This idea can be extended by preparing the entire file data in memory, and then using a single <i><b>fwrite</b></i> to write everything at once:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">fid = <span style="color: #0000FF;">fopen</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'test.dat'</span>, <span style="color:#A020F0;">'wb'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">tic</span>, <span style="color: #0000FF;">fwrite</span><span style="color: #080;">&#40;</span>fid,data<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">toc</span>
<span style="color: #0000FF;">fclose</span><span style="color: #080;">&#40;</span>fid<span style="color: #080;">&#41;</span>;
  =&gt; Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.014025</span> seconds.</pre></div></div>

<p>In fact, assembling the entire data in memory, within a long numeric or char array, and then using a single <i><b>fwrite</b></i> to save this array to file, is almost as fast as we can expect to get (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/325950">example</a>). Further improvement lies in optimizing the array assembly (which is CPU and memory-intensive) rather than the I/O itself.</p>
<p>In this example, the I/O was so fast (14mS) that it makes sense to write everything at once. But for enormously large data files and slower disks (I use a local SSD; network hard disks are <i>way</i> slower), writing the entire file&#8217;s data in this manner might take long minutes. In such cases, it is advisable to deliberately break up the data into smaller chunks, and <i><b>fwrite</b></i> them separately in a loop, all the time providing feedback to the user about the I/O&#8217;s progress. This could help improve the operation&#8217;s <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Perceived_performance"><i>perceived performance</i></a>. Here&#8217;s a bare-bones example:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">h = <span style="color: #0000FF;">waitbar</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>, <span style="color:#A020F0;">'Saving data...'</span>, <span style="color:#A020F0;">'Name'</span>,<span style="color:#A020F0;">'Saving data...'</span><span style="color: #080;">&#41;</span>;
cN = <span style="color: #33f;">100</span>;  <span style="color: #228B22;">% number of steps/chunks</span>
&nbsp;
<span style="color: #228B22;">% Divide the data into chunks (last chunk is smaller than the rest)</span>
dN = <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>data<span style="color: #080;">&#41;</span>;
dataIdx = <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> <span style="color: #0000FF;">round</span><span style="color: #080;">&#40;</span>dN/cN<span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> dN, dN+<span style="color: #33f;">1</span><span style="color: #080;">&#93;</span>;  <span style="color: #228B22;">% cN+1 chunk location indexes</span>
&nbsp;
<span style="color: #228B22;">% Save the data</span>
fid = <span style="color: #0000FF;">fopen</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'test.dat'</span>, <span style="color:#A020F0;">'Wb'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">for</span> chunkIdx = <span style="color: #33f;">0</span> <span style="color: #F0F;">:</span> cN-<span style="color: #33f;">1</span>
   <span style="color: #228B22;">% Update the progress bar</span>
   fraction = chunkIdx/cN;
   msg = <span style="color: #0000FF;">sprintf</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Saving data... (%d%% done)'</span>, <span style="color: #0000FF;">round</span><span style="color: #080;">&#40;</span><span style="color: #33f;">100</span>*fraction<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">waitbar</span><span style="color: #080;">&#40;</span>fraction, h, msg<span style="color: #080;">&#41;</span>;
&nbsp;
   <span style="color: #228B22;">% Save the next data chunk</span>
   chunkData = data<span style="color: #080;">&#40;</span>dataIdx<span style="color: #080;">&#40;</span>chunkIdx+<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> dataIdx<span style="color: #080;">&#40;</span>chunkIdx+<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">fwrite</span><span style="color: #080;">&#40;</span>fid,chunkData<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #0000FF;">fclose</span><span style="color: #080;">&#40;</span>fid<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">close</span><span style="color: #080;">&#40;</span>h<span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Of course, rather than using a plain-ol&#8217; <i><b>waitbar</b></i> window, we could integrate a progress bar directly into our GUI. Using my <a target="_blank" href="http://undocumentedmatlab.com/blog/setting-status-bar-components/"><i><b>statusbar</b></i> utility</a> is one way to do it, but there are of course many other possible ways to dynamically present progress:</p>
<p><center><div class="wp-caption aligncenter" style="width: 430px"><a target="_blank" href="http://undocumentedmatlab.com/blog/setting-status-bar-components/"><img alt="Dynamically updating progress using the statusbar utility (click for details)" src="http://undocumentedmatlab.com/images/statusbar_animated.gif" title="Dynamically updating progress using the statusbar utility (click for details)" width="420" height="266" /></a><p class="wp-caption-text">Dynamically updating progress using the statusbar utility</p></div></center></p>
<p>Note: the entire article above applies equally well to <i><b>fprintf</b></i> in addition to <i><b>fwrite</b></i>. Storing and loading data in binary format (using <i><b>fwrite/fread</b></i>) is often faster than text format (using <i><b>fprintf/fscanf/textscan</b></i>), so we should generally use text format only if the file needs to be human-readable for any reason.</p>
<p>Do you know of any other trick to store data efficiently? If so, please share it in a <a href="http://undocumentedmatlab.com/blog/improving-fwrite-performance/#respond">comment</a>.</p>
<p>Next week: some surprising performance aspects of Matlab&#8217;s <i><b>save</b></i> function.</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/improving-save-performance/' rel='bookmark' title='Improving save performance'>Improving save performance</a> <small>There are many different ways of improving Matlab's standard save function performance. ...</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/performance-scatter-vs-line/' rel='bookmark' title='Performance: scatter vs. line'>Performance: scatter vs. line</a> <small>In many circumstances, the line function can generate visually-identical plots as the scatter function, much faster...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/preallocation-performance/' rel='bookmark' title='Preallocation performance'>Preallocation performance</a> <small>Preallocation is a standard Matlab speedup technique. Still, it has several undocumented aspects. ...</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=2sYBjZssAiY:ofVBZo-iefk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=2sYBjZssAiY:ofVBZo-iefk:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=2sYBjZssAiY:ofVBZo-iefk:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=2sYBjZssAiY:ofVBZo-iefk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=2sYBjZssAiY:ofVBZo-iefk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=2sYBjZssAiY:ofVBZo-iefk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=2sYBjZssAiY:ofVBZo-iefk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=2sYBjZssAiY:ofVBZo-iefk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=2sYBjZssAiY:ofVBZo-iefk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=2sYBjZssAiY:ofVBZo-iefk:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/2sYBjZssAiY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/improving-fwrite-performance/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/improving-fwrite-performance/</feedburner:origLink></item>
		<item>
		<title>Setting class property types</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/35Mqk3AakFU/</link>
		<comments>http://undocumentedmatlab.com/blog/setting-class-property-types/#comments</comments>
		<pubDate>Thu, 18 Apr 2013 14:12:06 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[MCOS]]></category>
		<category><![CDATA[Object oriented]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[schema.prop]]></category>
		<category><![CDATA[UDD]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3725</guid>
		<description><![CDATA[Matlab's class properties have a simple and effective mechanism for setting their type. 
<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/types-of-undocumented-matlab-aspects/' rel='bookmark' title='Types of undocumented Matlab aspects'>Types of undocumented Matlab aspects</a> <small>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/extending-a-java-class-with-udd/' rel='bookmark' title='Extending a Java class with UDD'>Extending a Java class with UDD</a> <small>Java classes can easily be extended in Matlab, using pure Matlab code. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/setting-desktop-tab-completions/' rel='bookmark' title='Setting desktop tab completions'>Setting desktop tab completions</a> <small>The Matlab desktop's Command-Window tab-completion can be customized for user-defined functions...</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>When I wrote about the <a target="_blank" href="http://undocumentedmatlab.com/blog/undocumented-classdef-attributes/">undocumented aspects of classdef properties</a> half a year ago, I did not expect to learn of another major undocumented aspect in Matlab&#8217;s class-object system. last month I discovered the additional undocumented classdef Description and DetailedDescription attributes, and updated that article accordingly. But a few days ago I was pleasantly surprised to read Amro&#8217;s <a target="_blank" href="http://undocumentedmatlab.com/blog/undocumented-classdef-attributes/#comment-189056">comment</a> about an entirely new and undocumented aspect of Matlab MCOS classes.</p>
<p><a target="_blank" rel="nofollow" href="http://stackoverflow.com/users/97160/amro">Amro</a> is a top contributor on StackOverflow, where he frequently answers questions before I even get any subscription notification about them&#8230; His answers are generally characterized by a deep technical understanding of Matlab, and I&#8217;ve learned quite a lot from him in the past few years. This time was no different.</p>
<p>In a nutshell, Amro found an undocumented way to specify a class object property&#8217;s type, in such a way that would prevent accidental setting to an incompatible value. For example, if we have a class with properties <b>Width</b> and <b>Height</b>, we probably want to restrict their possible values to numbers, to prevent setting a string or struct value.</p>
<p>In UDD classes, we can do this easily by setting the property&#8217;s <b>DataType</b> meta-property. An easy way to do this is by setting the second argument of the <a target="_blank" href="http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/"><i><b>schema.prop</b></i> function</a>. A detailed explanation was provided <a target="_blank" href="http://undocumentedmatlab.com/blog/udd-properties/">here</a>.</p>
<p>We can still do this today, since UDD classes are still supported, side-by-side with the newer MCOS classes. Unfortunately, MCOS does not provide a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/matlab_oop/defining-properties.html">documented</a> way of specifying the property type as in UDD. </p>
<p>One simple way to prevent unintentional MCOS property updates is to <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/matlab_oop/implementing-a-set-get-interface-for-properties.html">override the property&#8217;s <i><b>set</b></i> method</a>. In fact, this was the <a target="_blank" rel="nofollow" href="http://stackoverflow.com/a/7192964/233829">solution</a> of Jonas, another StackOverflow heavyweight:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">classdef</span> myClass
   <span style="color: #0000FF;">properties</span>
      myProperty = <span style="color: #0000FF;">uint16</span><span style="color: #080;">&#40;</span><span style="color: #33f;">23</span><span style="color: #080;">&#41;</span>; <span style="color: #228B22;">%# specify default value using correct type</span>
   <span style="color: #0000FF;">end</span>
   <span style="color: #0000FF;">methods</span>
      <span style="color: #0000FF;">function</span> obj = <span style="color: #0000FF;">set</span>.<span style="">myProperty</span><span style="color: #080;">&#40;</span>obj,val<span style="color: #080;">&#41;</span>
         <span style="color: #0000FF;">if</span> ~<span style="color: #0000FF;">isa</span><span style="color: #080;">&#40;</span>val,<span style="color:#A020F0;">'uint16'</span><span style="color: #080;">&#41;</span>
            <span style="color: #0000FF;">error</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'only uint16 values allowed'</span><span style="color: #080;">&#41;</span>
         <span style="color: #0000FF;">end</span>
         <span style="color: #228B22;">%# assign the value</span>
         obj.<span style="">myProperty</span> = val;
      <span style="color: #0000FF;">end</span>
   <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div>

<p>But it turns out that there&#8217;s a much cleaner and simpler solution, <a target="_blank" rel="nofollow" href="http://stackoverflow.com/a/15992558/233829">provided</a> by Amro:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">classdef</span> Packet
    <span style="color: #0000FF;">properties</span>
        HeaderLength<span style="color: #F0F;">@</span><span style="color: #0000FF;">uint16</span>
        PayloadLength<span style="color: #F0F;">@</span><span style="color: #0000FF;">uint16</span> = <span style="color: #0000FF;">uint16</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;
        PacketType<span style="color: #F0F;">@</span><span style="color: #0000FF;">char</span>
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div>

<p><span id="more-3725"></span></p>
<p>As Amro notes, if you try to set a property with the wrong type, you get an error:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; p = Packet;
&gt;&gt; p.<span style="">PacketType</span> = <span style="color:#A020F0;">'tcp'</span>;  <span style="color: #228B22;">% ok</span>
&gt;&gt; p.<span style="">HeaderLength</span> = <span style="color: #33f;">100</span>;  <span style="color: #228B22;">% not ok - should be a uint16</span>
<span style="color: #0000FF;">While</span> setting the <span style="color:#A020F0;">'HeaderLength'</span> property of Packet<span style="color: #F0F;">:</span>
Value must be <span style="color:#A020F0;">'uint16'</span>.</pre></div></div>

<p>This syntax apparently supports all primitive types (<i><b>char, int32, double, struct, cell</b></i> etc.), in addition to any user-defined ones (just use any class name).</p>
<p>Note that setting the type as above seems to override any <i><b>set</b></i> method that may have been specified for the property.</p>
<p>Amro came across this syntax in an internal class in R2013a (<i>toolboxdir(&#8216;matlab&#8217;)/graphics/+graphics/+internal/+figfile/@FigFile/FigFile.m</i>), but it also worked in R2012a, and probably older versions as well&#8230;</p>
<p>I admit there&#8217;s not much original work here by me &#8211; it&#8217;s basically all by Amro (and Donn Shull for the UDD part). But I thought it&#8217;s important enough to bring to the attention of the community. </p>
<p>I love to discover such undocumented treasures by digging in Matlab&#8217;s function. If you ever discover other such buried treasures, please do let me know by email or a comment.</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/types-of-undocumented-matlab-aspects/' rel='bookmark' title='Types of undocumented Matlab aspects'>Types of undocumented Matlab aspects</a> <small>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/extending-a-java-class-with-udd/' rel='bookmark' title='Extending a Java class with UDD'>Extending a Java class with UDD</a> <small>Java classes can easily be extended in Matlab, using pure Matlab code. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/setting-desktop-tab-completions/' rel='bookmark' title='Setting desktop tab completions'>Setting desktop tab completions</a> <small>The Matlab desktop's Command-Window tab-completion can be customized for user-defined functions...</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=35Mqk3AakFU:FWzWRhVXmlQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=35Mqk3AakFU:FWzWRhVXmlQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=35Mqk3AakFU:FWzWRhVXmlQ:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=35Mqk3AakFU:FWzWRhVXmlQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=35Mqk3AakFU:FWzWRhVXmlQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=35Mqk3AakFU:FWzWRhVXmlQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=35Mqk3AakFU:FWzWRhVXmlQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=35Mqk3AakFU:FWzWRhVXmlQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=35Mqk3AakFU:FWzWRhVXmlQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=35Mqk3AakFU:FWzWRhVXmlQ:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/35Mqk3AakFU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/setting-class-property-types/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/setting-class-property-types/</feedburner:origLink></item>
		<item>
		<title>Parsing mlint (Code Analyzer) output</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/6qFUoQ5OiaA/</link>
		<comments>http://undocumentedmatlab.com/blog/parsing-mlint-code-analyzer-output/#comments</comments>
		<pubDate>Wed, 10 Apr 2013 18:00:28 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Mex]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pure Matlab]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3713</guid>
		<description><![CDATA[The Matlab Code Analyzer (mlint) has a lot of undocumented functionality just waiting to be used.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/running-vb-code-in-matlab/' rel='bookmark' title='Running VB code in Matlab'>Running VB code in Matlab</a> <small>Matlab does not natively enable running VB code, but a nice trick enables us to do just that...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/undocumented-scatter-plot-behavior/' rel='bookmark' title='Undocumented scatter plot behavior'>Undocumented scatter plot behavior</a> <small>The scatter plot function has an undocumented behavior when plotting more than 100 points: it returns a single unified patch object handle, rather than a patch handle for each specific...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/more-undocumented-timing-features/' rel='bookmark' title='More undocumented timing features'>More undocumented timing features</a> <small>There are several undocumented ways in Matlab to get CPU and clock data...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/' rel='bookmark' title='tic / toc &#8211; undocumented option'>tic / toc &#8211; undocumented option</a> <small>Matlab's built-in tic/toc functions have an undocumented option enabling multiple nested clockings...</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Mlint, Matlab&#8217;s static code-analysis parser, was written by <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Stephen_C._Johnson">Stephen Johnson</a> (the original developer of the enormously successful <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Lint_(software)">lint</a> parser for C/C++ back in 1977), when he was lured by MathWorks in 2002 to develop a similar tool for Matlab. Since its development (in R14 I believe), and especially since its incorporation in Matlab&#8217;s Editor in R2006a (Matlab 7.2), mlint has become a very important tool for reporting potential problems in m-files. </p>
<p>Unfortunately, to this day (R2013a), there is no <i>documented</i> manner of programmatically separating mlint warnings and errors, nor for accessing any of the multitude of features that are readily available in mlint. Naturally, there is (and has always been) an undocumented back door.</p>
<p>From its earliest beginnings, mlint has relied on C code (presumably modeled after lint). For many years mlint relied on a mex file (<i>%matlabroot%/toolbox/matlab/codetools/mlintmex.mex*</i>), which is basically just a wrapper for <i>mlint.dll</i> where the core algorithm resides. In recent releases, <i><b>mlintmex</b></i>, just like many other core mex files, was ported into a core Matlab library (<i>libmwbuiltins.dll</i> on Windows). However, the name and interface of the <i><b>mlintmex</b></i> function have remained unchanged over the years. Wrapping the core <i><b>mlintmex</b></i> function is the <i><b>mlint</b></i> m-function (<i>%matlabroot%/toolbox/matlab/codetools/mlint.m</i>) that calls <i><b>mlintmex</b></i> internally. In R2011b (Matlab 7.13) its official function name has changed to <i><b>checkcode</b></i>, although this was never documented in the release notes for some reason. However, using <i><b>mlint</b></i> still works even today. Wrapping all that is the <i><b>mlintrpt</b></i> function, which calls <i><b>mlint/checkcode</b></i> internally.</p>
<p>The core function <i><b>mlintmex</b></i> returns a long string with embedded newlines to separate the messages. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&gt;&gt;</span> str <span style="color: #339933;">=</span> mlintmex<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'perfTest.m'</span><span style="color: #009900;">&#41;</span>
str <span style="color: #339933;">=</span> 
L <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#40;</span>C <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> The value assigned to variable <span style="color: #0000ff;">'A'</span> might be unused.
<span style="color: #006633;">L</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#40;</span>C <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> The value assigned to variable <span style="color: #0000ff;">'B'</span> might be unused.
<span style="color: #006633;">L</span> <span style="color: #cc66cc;">5</span> <span style="color: #009900;">&#40;</span>C <span style="color: #cc66cc;">1</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> Variable <span style="color: #0000ff;">'ops'</span>, apparently a structure, is changed but the value seems to be unused.
<span style="color: #006633;">L</span> <span style="color: #cc66cc;">12</span> <span style="color: #009900;">&#40;</span>C <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">This</span> statement <span style="color: #009900;">&#40;</span>and possibly following ones<span style="color: #009900;">&#41;</span> cannot be reached.
<span style="color: #006633;">L</span> <span style="color: #cc66cc;">53</span> <span style="color: #009900;">&#40;</span>C <span style="color: #cc66cc;">19</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> The function <span style="color: #0000ff;">'subFunc'</span> might be unused.
<span style="color: #006633;">L</span> <span style="color: #cc66cc;">53</span> <span style="color: #009900;">&#40;</span>C <span style="color: #cc66cc;">27</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">35</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> Input argument <span style="color: #0000ff;">'iteration'</span> might be unused. <span style="color: #000000; font-weight: bold;">If</span> <span style="color: #000000; font-weight: bold;">this</span> is OK, consider replacing it by ~.</pre></div></div>

<p><span id="more-3713"></span></p>
<p>We can parse this long string ourselves, but there is no need since <i><b>mlint/checkcode</b></i> do this for us, returning a struct array:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&gt;&gt;</span> results <span style="color: #339933;">=</span> mlint<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'perfTest.m'</span><span style="color: #009900;">&#41;</span>
results <span style="color: #339933;">=</span> 
6x1 struct array with fields<span style="color: #339933;">:</span>
    message
    line
    column
    fix
<span style="color: #339933;">&gt;&gt;</span> results<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span>
ans <span style="color: #339933;">=</span> 
    message<span style="color: #339933;">:</span> <span style="color: #0000ff;">'The function '</span>subFunc<span style="color: #0000ff;">' might be unused.'</span>
       line<span style="color: #339933;">:</span> <span style="color: #cc66cc;">53</span>
     column<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">19</span> <span style="color: #cc66cc;">25</span><span style="color: #009900;">&#93;</span>
        fix<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span></pre></div></div>

<p>As can be seen, the message severity (warning/error) does not appear. This severity is obviously available since it is integrated in the Editor and the Code Analyzer report &#8211; orange for warnings, red for errors. </p>
<p>In one of my projects I needed to enable the user to dynamically create executable Matlab code that would then be run interactively. This enabled users to create dynamic data analyses functions without actually needing to know Matlab or to code all the nuts-and-bolts of a regular Matlab function. For this I needed to display warnings and errors-on-the-fly (the dynamic cell tooltips used a <a target="_blank" href="http://undocumentedmatlab.com/blog/uitable-cell-colors/#colors">custom table cell-renderer</a>). Here&#8217;s the end-result:</p>
<p><center><br />
<div class="wp-caption aligncenter" style="width: 666px"><img alt="Analysis definition panel" src="http://UndocumentedMatlab.com/images/IDS_DefsAnalyses2.png" title="Analysis definition panel" width="656" /><p class="wp-caption-text">Analysis definition panel</p></div><br />
<div class="wp-caption aligncenter" style="width: 647px"><img alt="Dynamic analysis alert tooltips" src="http://UndocumentedMatlab.com/images/IDS_DefsAnalyses3b.png" title="Dynamic analysis alert tooltips" width="508" /><br /><img alt="Dynamic analysis alert tooltips" src="http://UndocumentedMatlab.com/images/IDS_DefsAnalyses3c.png" title="Dynamic analysis alert tooltips" width="637" /><p class="wp-caption-text">Dynamic analysis alert tooltips</p></div><br />
</center></p>
<p>My <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/255839#755939">solution</a> was to use <i><b>mlintmex</b></i>, as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Get the relevant message strings</span>
errMsgs = mlintmex<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'-m2'</span>, srcFileName<span style="color: #080;">&#41;</span>;
allMsgs = mlintmex<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'-m0'</span>, srcFileName<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Parse the strings to find newline characters</span>
numErrors = <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>strfind<span style="color: #080;">&#40;</span>regexprep<span style="color: #080;">&#40;</span>errMsgs,<span style="color:#A020F0;">'\*\*\*.*'</span>,<span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>,<span style="color: #0000FF;">char</span><span style="color: #080;">&#40;</span><span style="color: #33f;">10</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
numAllMsg = <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>strfind<span style="color: #080;">&#40;</span>regexprep<span style="color: #080;">&#40;</span>allMsgs,<span style="color:#A020F0;">'\*\*\*.*'</span>,<span style="color:#A020F0;">''</span><span style="color: #080;">&#41;</span>,<span style="color: #0000FF;">char</span><span style="color: #080;">&#40;</span><span style="color: #33f;">10</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
numWarns = numAllMsg - numErrors;</pre></div></div>

<p>(and from the messages themselves [<code>errMsgs,allMsgs</code>] I extracted the actual error/warning location)</p>
<p>Alternatively, I could have used <i><b>mlint</b></i> directly, as I have recently <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/answers/54903-does-checkcode-return-the-status-of-the-message-indicator-box-i-e-red-orange-green">explained</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Note that mlint returns struct arrays, so the following are all structs, not strings</span>
errMsgs = mlint<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'-m2'</span>,srcFileNames<span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% m2 = errors only</span>
m1Msgs  = mlint<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'-m1'</span>,srcFileNames<span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% m1 = errors and severe warnings only</span>
allMsgs = mlint<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'-m0'</span>,srcFileNames<span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% m0 = all errors and warnings</span></pre></div></div>

<p>The original information about <i><b>mlintmex</b></i> and the undocumented -m0/m1/m2 options came from <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/authors/4309">Urs (us) Schwartz</a>, whose contributions are an endless source of such gems. Urs also <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/255839#756892">provided</a> a list of other undocumented <i><b>mlint</b></i> options:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color:#A020F0;">'-all'</span>
<span style="color:#A020F0;">'-allmsg'</span>
<span style="color:#A020F0;">'-amb'</span>
<span style="color:#A020F0;">'-body'</span>
<span style="color:#A020F0;">'-callops'</span>
<span style="color:#A020F0;">'-calls'</span>
<span style="color:#A020F0;">'-com'</span>
<span style="color:#A020F0;">'-cyc'</span>
<span style="color: #228B22;">% '-db'       % == -set + -ud + -tab</span>
<span style="color:#A020F0;">'-dty'</span>
<span style="color:#A020F0;">'-edit'</span>
<span style="color:#A020F0;">'-en'</span>         <span style="color: #228B22;">% messages in English</span>
<span style="color:#A020F0;">'-id'</span>
<span style="color:#A020F0;">'-ja'</span>         <span style="color: #228B22;">% messages in Japanese</span>
<span style="color:#A020F0;">'-lex'</span>
<span style="color:#A020F0;">'-m0'</span>         <span style="color: #228B22;">% + other opt</span>
<span style="color:#A020F0;">'-m1'</span>         <span style="color: #228B22;">% + other opt</span>
<span style="color:#A020F0;">'-m2'</span>         <span style="color: #228B22;">% + other opt</span>
<span style="color:#A020F0;">'-m3'</span>         <span style="color: #228B22;">% + other opt</span>
<span style="color:#A020F0;">'-mess'</span>
<span style="color:#A020F0;">'-msg'</span>
<span style="color:#A020F0;">'-notok'</span>
<span style="color:#A020F0;">'-pf'</span>
<span style="color:#A020F0;">'-set'</span>
<span style="color:#A020F0;">'-spmd'</span>
<span style="color:#A020F0;">'-stmt'</span>
<span style="color:#A020F0;">'-tab'</span>
<span style="color:#A020F0;">'-tmtree'</span>
<span style="color:#A020F0;">'-tmw'</span>        <span style="color: #228B22;">% not valid anymore</span>
<span style="color:#A020F0;">'-toks'</span>
<span style="color:#A020F0;">'-tree'</span>
<span style="color:#A020F0;">'-ty'</span>
<span style="color:#A020F0;">'-ud'</span>
<span style="color:#A020F0;">'-yacc'</span>       <span style="color: #228B22;">% ONLY: !mlint FILE -yacc -...</span></pre></div></div>

<p>to which were added in recent years &#8216;-eml&#8217;, &#8216;-codegen&#8217; etc. &#8211; see the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/checkcode.html"><i><b>checkcode</b></i> doc page</a>. Also note that not all Matlab releases support all options. For example, &#8216;-tmw&#8217; is ignored in R2013a, returning the same data as &#8216;-all&#8217; plus a warning about the ignored option.</p>
<p>Urs prepared a short utility called <a target="_blank" href="http://UndocumentedMatlab.com/files/doli.m">doli</a> that accepts an m-file name and returns a struct whose fields are the respective outputs of <i><b>mlint</b></i> for each of the corresponding options:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&gt;&gt;</span> results <span style="color: #339933;">=</span> doli<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'perfTest.m'</span><span style="color: #009900;">&#41;</span>
MLINT <span style="color: #339933;">&gt;</span>   C<span style="color: #339933;">:</span>\Yair\Books\MATLAB Performance Tuning\Code\perfTest.<span style="color: #006633;">m</span>
OPTION<span style="color: #339933;">&gt;</span>   <span style="color: #339933;">-</span>all       <span style="color: #cc66cc;">6</span>
OPTION<span style="color: #339933;">&gt;</span>   <span style="color: #339933;">-</span>allmsg    <span style="color: #cc66cc;">501</span>
OPTION<span style="color: #339933;">&gt;</span>   <span style="color: #339933;">-</span>amb       <span style="color: #cc66cc;">17</span>
OPTION<span style="color: #339933;">&gt;</span>   <span style="color: #339933;">-</span>body      <span style="color: #cc66cc;">6</span>
OPTION<span style="color: #339933;">&gt;</span>   <span style="color: #339933;">-</span>callops   <span style="color: #cc66cc;">15</span>
OPTION<span style="color: #339933;">&gt;</span>   <span style="color: #339933;">-</span>calls     <span style="color: #cc66cc;">15</span>
OPTION<span style="color: #339933;">&gt;</span>   <span style="color: #339933;">-</span>com       <span style="color: #cc66cc;">6</span>
OPTION<span style="color: #339933;">&gt;</span>   <span style="color: #339933;">-</span>cyc       <span style="color: #cc66cc;">8</span>
OPTION<span style="color: #339933;">&gt;</span>   <span style="color: #339933;">-</span>dty       <span style="color: #cc66cc;">162</span>
OPTION<span style="color: #339933;">&gt;</span>   <span style="color: #339933;">-</span>edit      <span style="color: #cc66cc;">92</span>
OPTION<span style="color: #339933;">&gt;</span>   <span style="color: #339933;">-</span>en        <span style="color: #cc66cc;">7</span>
...</pre></div></div>

<p>Some of these options are used by Urs&#8217; <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/15924-farg-a-pedestrian-m-file-parser-showing-all-used-functions-syntax"><i><b>farg</b></i></a> and <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17291-fdep-a-pedestrian-function-dependencies-finder"><i><b>fdep</b></i></a> utilities. Their usage of <i><b>mlint</b></i> rather than direct m-code parsing, is part of the reason that these functions are so lightningly fast.</p>
<p>For example, we can use the &#8216;-calls&#8217; options to parse an m-file and get the names, type, and code location of its contained functions (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/145245#365590">explanation</a>):</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&gt;&gt;</span> mlint<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-calls'</span>,<span style="color: #0000ff;">'perfTest.m'</span><span style="color: #009900;">&#41;</span>
M0 <span style="color: #cc66cc;">1</span> <span style="color: #cc66cc;">10</span> perfTest
E0 <span style="color: #cc66cc;">51</span> <span style="color: #cc66cc;">3</span> perfTest
U1 <span style="color: #cc66cc;">3</span> <span style="color: #cc66cc;">5</span> randi
U1 <span style="color: #cc66cc;">4</span> <span style="color: #cc66cc;">5</span> num2cell
U1 <span style="color: #cc66cc;">4</span> <span style="color: #cc66cc;">14</span> randn
U1 <span style="color: #cc66cc;">6</span> <span style="color: #cc66cc;">1</span> whos
U1 <span style="color: #cc66cc;">7</span> <span style="color: #cc66cc;">1</span> tic
U1 <span style="color: #cc66cc;">7</span> <span style="color: #cc66cc;">6</span> save
U1 <span style="color: #cc66cc;">7</span> <span style="color: #cc66cc;">45</span> toc
U1 <span style="color: #cc66cc;">9</span> <span style="color: #cc66cc;">6</span> savefast
S0 <span style="color: #cc66cc;">53</span> <span style="color: #cc66cc;">19</span> subFunc
E0 <span style="color: #cc66cc;">60</span> <span style="color: #cc66cc;">3</span> subFunc
U1 <span style="color: #cc66cc;">55</span> <span style="color: #cc66cc;">8</span> isempty
U1 <span style="color: #cc66cc;">56</span> <span style="color: #cc66cc;">20</span> load
U1 <span style="color: #cc66cc;">57</span> <span style="color: #cc66cc;">29</span> sin</pre></div></div>

<p>With so many useful features, I really cannot understand why they were never exposed to the public in a documented manner. After all, they have remained pretty-much unchanged for many years and can provide enormous benefits for developers of unit-tests and interactive analysis frameworks (as I have shown above).</p>
<p>As a side-note, in R2010a (Matlab 7.10), mlint was renamed &#8220;Code Analyzer&#8221;, but this was really just a name change &#8211; its core functionality has changed little in the past decade. Some might argue that new checks were added and the Editor interface has improved by allowing auto-fixes and message suppression. But for a tool that is over a decade old (much more, if you count lint&#8217;s development), I contend that these are not much. Don&#8217;t get me wrong &#8211; I have the utmost respect for Steve. Serious unix C/C++ development relies on his lint and yacc tools on a regular basis. I think they show astonishing ingenuity and intelligence. It&#8217;s just that I had expected more after a decade of mlint development (I bet it&#8217;s not due to Steve suddenly losing the touch). </p>
<p><b><u>Addendum:</u></b> A little birdie tells me that Steve left MathWorks a few years ago, which does explain things&#8230; I apologize to Steve for any misguided snide on my part. As I said above, I have nothing but the utmost respect for his work. The question of why MathWorks left his mlint work hanging without serious continuation remains open.</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/running-vb-code-in-matlab/' rel='bookmark' title='Running VB code in Matlab'>Running VB code in Matlab</a> <small>Matlab does not natively enable running VB code, but a nice trick enables us to do just that...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/undocumented-scatter-plot-behavior/' rel='bookmark' title='Undocumented scatter plot behavior'>Undocumented scatter plot behavior</a> <small>The scatter plot function has an undocumented behavior when plotting more than 100 points: it returns a single unified patch object handle, rather than a patch handle for each specific...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/more-undocumented-timing-features/' rel='bookmark' title='More undocumented timing features'>More undocumented timing features</a> <small>There are several undocumented ways in Matlab to get CPU and clock data...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/tic-toc-undocumented-option/' rel='bookmark' title='tic / toc &#8211; undocumented option'>tic / toc &#8211; undocumented option</a> <small>Matlab's built-in tic/toc functions have an undocumented option enabling multiple nested clockings...</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=6qFUoQ5OiaA:uJugmVeKqpY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=6qFUoQ5OiaA:uJugmVeKqpY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=6qFUoQ5OiaA:uJugmVeKqpY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=6qFUoQ5OiaA:uJugmVeKqpY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=6qFUoQ5OiaA:uJugmVeKqpY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=6qFUoQ5OiaA:uJugmVeKqpY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=6qFUoQ5OiaA:uJugmVeKqpY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=6qFUoQ5OiaA:uJugmVeKqpY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=6qFUoQ5OiaA:uJugmVeKqpY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=6qFUoQ5OiaA:uJugmVeKqpY:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/6qFUoQ5OiaA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/parsing-mlint-code-analyzer-output/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/parsing-mlint-code-analyzer-output/</feedburner:origLink></item>
		<item>
		<title>ishghandle’s undocumented input parameter</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/RwROTQHGURA/</link>
		<comments>http://undocumentedmatlab.com/blog/ishghandle-undocumented-input-parameter/#comments</comments>
		<pubDate>Wed, 27 Mar 2013 21:06:53 +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[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Pure Matlab]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3699</guid>
		<description><![CDATA[The built-in function ishghandle accepts a second input argument with the expected handle type. 
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/hgs-undocumented-parameters-interface/' rel='bookmark' title='HG&#8217;s undocumented parameters interface'>HG&#8217;s undocumented parameters interface</a> <small>Some HG functions also accept inputs parameters in a struct fields rather than the normal P-V pairs format. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/undocumented-scatter-plot-jitter/' rel='bookmark' title='Undocumented scatter plot jitter'>Undocumented scatter plot jitter</a> <small>Matlab's scatter plot can automatically jitter data to enable better visualization of distribution density. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/undocumented-scatter-plot-behavior/' rel='bookmark' title='Undocumented scatter plot behavior'>Undocumented scatter plot behavior</a> <small>The scatter plot function has an undocumented behavior when plotting more than 100 points: it returns a single unified patch object handle, rather than a patch handle for each specific...</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>Two weeks ago I wrote about Matlab Handle Graphics (HG) undocumented <a target="_blank" href="http://undocumentedmatlab.com/blog/hgs-undocumented-parameters-interface/">acceptance of structs</a> as input parameter to some plotting functions. Continuing in a related matter, today I expose an undocumented input parameter for HG&#8217;s <i><b>ishghandle</b></i> function.</p>
<p><i><b>ishghandle</b></i> is a fully-documented built-in Matlab function that returns a <code>logical</code> flag indicating whether the specified input is a valid HG handle or not. The input could be an invalid handle for several reasons: Perhaps it is not an HG handle in the first place, or perhaps the corresponding HG object has since been deleted (for example, its parent figure window was closed). The usage is very simple:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">if</span> ishghandle<span style="color: #080;">&#40;</span>myHandle<span style="color: #080;">&#41;</span>
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>myHandle, <span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div>

<p>But what if <code>myHandle</code> could be any of several possible HG types (e.g., plot line, patch or 3D surface) and our logic depends on the type? Of course, we could always add an extra condition to the logic:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">if</span> ishghandle<span style="color: #080;">&#40;</span>myHandle<span style="color: #080;">&#41;</span> <span style="color: #F0F;">&amp;&amp;</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>h,<span style="color:#A020F0;">'type'</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'surface'</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%or: if ishghandle(myHandle) &amp;&amp; isa(handle(h),'surface')</span>
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>myHandle, <span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div>

<p>There&#8217;s an undocumented alternative: we can simply specify the expected type as a second input argument to <i><b>ishghandle</b></i>. This is in fact the simplest and fastest alternative:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">if</span> ishghandle<span style="color: #080;">&#40;</span>myHandle,<span style="color:#A020F0;">'surface'</span><span style="color: #080;">&#41;</span>
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>myHandle, <span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div>

<p><span id="more-3699"></span></p>
<p>If the second input argument is specified, then <i><b>ishghandle</b></i> will only return <code>true</code> if both (1) the input handle is a valid HG handle and (2) if its type is the specified second input argument. <i><b>ishghandle</b></i>&#8216;s second input arg is case in-sensitive, so we can enter either &#8216;surface&#8217;, &#8216;Surface&#8217; or &#8216;SURFACE&#8217; (unlike the <i><b>isa</b></i> function, which is case-sensitive for some unknown reason).</p>
<p>I&#8217;ve first came across this <i><b>ishghandle</b></i> feature in a <a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/14732064/implementing-multiple-syntaxes-for-a-matlab-plot-function">post</a> by Sam Roberts. While the second-arg syntax is not very common in the Matlab code corpus, it does appear in several dozen places, for example:</p>
<ul>
<li><i>%matlabroot%/toolbox/matlab/graph2d/plotedit.m</i>: <code>if any(ishghandle(varargin{1}, 'figure'))</code></li>
<li><i>%matlabroot%/toolbox/matlab/graph2d/subplot.m</i>: <code>if ~ishghandle(h, 'axes')</code></li>
<li><i>%matlabroot%/toolbox/matlab/graph3d/camlight.m</i>: <code>...any(ishghandle(args{1},'light'))</code></li>
<li><i>%matlabroot%/toolbox/matlab/graph3d/colordef.m</i>: <code>...~ishghandle(arg1, 'figure') &#038;&#038; ~ishghandle(arg1, 'root')</code></li>
<li><i>%matlabroot%/toolbox/matlab/graph3d/objbounds.m</i>: <code>if (ishghandle(h(i),'surface') || ishghandle(h(i),'line') || ishghandle(h(i),'image'))</code></li>
<li><i>%matlabroot%/toolbox/matlab/graph3d/objbounds.m</i>: <code>elseif ishghandle(h(i),'patch')</code></li>
<li><i>%matlabroot%/toolbox/matlab/graphics/@graphics/@pan/schema.m</i>: <code>... ~ishghandle(valueProposed,'uicontextmenu')</code></li>
<li><i>%matlabroot%/toolbox/matlab/scribe/selectobject.m</i>: <code>if ~ishghandle(obj,'axes') &#038;&#038; ~ishghandle(obj,'figure') &#038;&#038; ~ishghandle(obj,'uipanel')</code></li>
<li><i>%matlabroot%/toolbox/matlab/uitools/@uitools/@uimode/createuimode.m</i>: <code>... ishghandle(figureState.LastObject,'uicontrol') || ishghandle(figureState.LastObject,'uitable')</code></li>
<li><i>%matlabroot%/toolbox/matlab/uitools/private/javacomponentundoc_helper.m</i>: <code>ishghandle(hParent, 'uicontainer') || ishghandle(hParent, 'uiflowcontainer') || ishghandle(hParent, 'uigridcontainer') ... ishghandle(hParent, 'uitoolbar') ... ishghandle(hParent, 'uisplittool') || ishghandle(hParent, 'uitogglesplittool') ... ishghandle(hParent, 'hgjavacomponent')</code></li>
<li><i>%matlabroot%/toolbox/matlab/uitools/winmenu.m</i>: <code>... ~ishghandle(h,'uimenu')</code></li>
<li><i>%matlabroot%/toolbox/matlab/guide/guidemfile.m</i>: <code>mychildren(ishghandle(mychildren,'hggroup')) = [];</code></li>
</ul>
<p>Did you happen to notice any other stock Matlab function with undocumented input arguments? If so, please write a short comment about it <a href="http://UndocumentedMatlab.com/blog/ishghandle-undocumented-input-parameter/#respond">below</a>.</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/hgs-undocumented-parameters-interface/' rel='bookmark' title='HG&#8217;s undocumented parameters interface'>HG&#8217;s undocumented parameters interface</a> <small>Some HG functions also accept inputs parameters in a struct fields rather than the normal P-V pairs format. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/undocumented-scatter-plot-jitter/' rel='bookmark' title='Undocumented scatter plot jitter'>Undocumented scatter plot jitter</a> <small>Matlab's scatter plot can automatically jitter data to enable better visualization of distribution density. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/undocumented-scatter-plot-behavior/' rel='bookmark' title='Undocumented scatter plot behavior'>Undocumented scatter plot behavior</a> <small>The scatter plot function has an undocumented behavior when plotting more than 100 points: it returns a single unified patch object handle, rather than a patch handle for each specific...</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><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=RwROTQHGURA:IFGTVTwPFNw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=RwROTQHGURA:IFGTVTwPFNw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=RwROTQHGURA:IFGTVTwPFNw:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=RwROTQHGURA:IFGTVTwPFNw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=RwROTQHGURA:IFGTVTwPFNw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=RwROTQHGURA:IFGTVTwPFNw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=RwROTQHGURA:IFGTVTwPFNw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=RwROTQHGURA:IFGTVTwPFNw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=RwROTQHGURA:IFGTVTwPFNw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=RwROTQHGURA:IFGTVTwPFNw:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/RwROTQHGURA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/ishghandle-undocumented-input-parameter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/ishghandle-undocumented-input-parameter/</feedburner:origLink></item>
		<item>
		<title>JTattoo look-and-feel demo</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/P5jbuYVKCw8/</link>
		<comments>http://undocumentedmatlab.com/blog/jtattoo-look-and-feel-demo/#comments</comments>
		<pubDate>Wed, 20 Mar 2013 16:00:11 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[Karthik Ponudurai]]></category>
		<category><![CDATA[uicontrol]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3687</guid>
		<description><![CDATA[A demo GUI that shows the effects of using different look-and-feels, including the JTatoo library, is presented.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/modifying-matlab-look-and-feel/' rel='bookmark' title='Modifying Matlab&#8217;s Look-and-Feel'>Modifying Matlab&#8217;s Look-and-Feel</a> <small>Matlab's entire Look-and-Feel (PLAF, or L&F) can be modified at the control or application level - this article shows how...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/additional-uicontrol-tooltip-hacks/' rel='bookmark' title='Additional uicontrol tooltip hacks'>Additional uicontrol tooltip hacks</a> <small>Matlab's uicontrol tooltips have several limitations that can be overcome using the control's underlying Java object....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/inactive-control-tooltips-event-chaining/' rel='bookmark' title='Inactive Control Tooltips &amp; Event Chaining'>Inactive Control Tooltips &#038; Event Chaining</a> <small>Inactive Matlab uicontrols cannot normally display their tooltips. This article shows how to do this with a combination of undocumented Matlab and Java hacks....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/setting-line-position-in-edit-box-uicontrol/' rel='bookmark' title='Setting line position in an edit-box uicontrol'>Setting line position in an edit-box uicontrol</a> <small>Matlab uicontrols have many useful features that are only available via Java. Here's how to access them....</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Three years ago, I wrote an article about modifying <a target="_blank" href="http://undocumentedmatlab.com/blog/modifying-matlab-look-and-feel/">Matlab&#8217;s look-and-feel</a> (L&#038;F, or LnF), using Java&#8217;s built-in support for replaceable LnFs. To date, that article has 27 comments by 13 different commenters (plus 20 responses by me), making it the second most active article on this website. I decided to follow up on that article with a demo that shows the effects that different L&#038;Fs have on GUI controls, and a demonstration of the JTattoo library of professional L&#038;Fs. </p>
<p>Today&#8217;s article and the demo are based on original work by <a target="_blank" href="http://undocumentedmatlab.com/blog/tag/karthik-ponudurai/">Karthik Ponudurai</a>, who has written a guest article here about an interesting <a target="_blank" href="http://undocumentedmatlab.com/blog/matlab-java-interface-using-static-control/">technique to interface a Java GUI to a Matlab application</a>, a couple of years ago.</p>
<p><center><div class="wp-caption aligncenter" style="width: 510px"><a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/40866-jtattoo-look-and-feel-demo-gui"><img alt="Demo of using different Look-and-Feels in Matlab GUI" src="http://www.mathworks.com/matlabcentral/fx_files/40866/2/JTattooDemo_animated.gif" title="Demo of using different Look-and-Feels in Matlab GUI" width="500" height="421" /></a><p class="wp-caption-text">Demo of using different Look-and-Feels in Matlab GUI</p></div></center></p>
<p><span id="more-3687"></span></p>
<p><a target="_blank" rel="nofollow" href="http://www.jtattoo.net/">JTattoo</a> is a 3rd-party open-source library. The purpose of including it in the demo, in addition to its natural use as a professional set of L&#038;Fs, is to demonstrate how easy it is to integrate 3rd-party L&#038;Fs in Matlab. In the demo I use the current latest <a target="_blank" rel="nofollow" href="http://www.jtattoo.net/Download.html">available</a> JTattoo library (1.6.7), but you can always download the latest version and replace the <i>JTattoo.jar</i> file. JTattoo contains a large set of different L&#038;Fs that can be used independently (<a target="_blank" rel="nofollow" href="http://www.jtattoo.net/ScreenShots.html">screenshots</a>). The nice thing about L&#038;Fs is that since all Matlab GUI is based on Java Swing, the new L&#038;Fs automatically affect Matlab controls just like native Java ones. </p>
<p>The demo can be <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/40866-jtattoo-look-and-feel-demo-gui">downloaded</a> from the Matlab File Exchange. After downloading, unzip it into any folder on your Matlab path and run <i>JTattooDemo.m</i>.</p>
<p>A Matlab figure is displayed with two panels, one containing Matlab uicontrols (within a simple <a target="_blank" href="http://undocumentedmatlab.com/blog/matlab-layout-managers-uicontainer-and-relatives/"><i><b>uiflowcontainer</b></i></a>) and the other containing Java components. </p>
<p>Two main menus are available: <i>System</i> enables selecting the standard Swing L&#038;Fs that are installed on your system (this varies a bit between platforms and Matlab releases); <i>JTattoo</i> enables selecting one of the JTattoo L&#038;Fs. Once the user selects any of the L&#038;F menu items, the entire figure is updated. This is done by calling <code>javax.swing.SwingUtilities.updateComponentTreeUI()</code> on the figure&#8217;s <a target="_blank" href="http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/#JavaFrame">Java Frame</a>&#8216;s content pane. Both the Matlab and the Java controls within the figure are automatically updated by this Swing function to reflect the newly-selected L&#038;F. Care is taken to update the L&#038;F on the <a target="_blank" href="http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/">EDT</a>, to prevent racing-condition issues.</p>
<p>It should be noted that the demo resets the L&#038;F after updating the figure, otherwise any new figure or window would open using the newly-selected L&#038;F. This is done in the <i>updateInterface</i> function as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> updateInterface<span style="color: #080;">&#40;</span> lookandfeel <span style="color: #080;">&#41;</span>
&nbsp;
    <span style="color: #228B22;">% Preserve the original L&amp;F, before updating</span>
    originalLnF = javax.<span style="">swing</span>.<span style="">UIManager</span>.<span style="">getLookAndFeel</span>;
&nbsp;
    <span style="color: #228B22;">% Update the L&amp;F in the demo figure as requested</span>
    <span style="color: #F0F;">...</span> <span style="color: #080;">&#40;</span><span style="color: #0000FF;">all</span> the existing code within the <span style="color: #0000FF;">function</span><span style="color: #080;">&#41;</span>
&nbsp;
    <span style="color: #228B22;">% Restore the original L&amp;F for any new figure/window</span>
    javax.<span style="">swing</span>.<span style="">UIManager</span>.<span style="">setLookAndFeel</span><span style="color: #080;">&#40;</span>originalLnF<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% updateInterface</span></pre></div></div>

<p>Note that after changing the L&#038;Fs several times, some L&#038;F properties night get &#8220;mixed-up&#8221; causing odd-looking L&#038;Fs. The simplest solution in this case is to restart Matlab&#8230;</p>
<p><center><div class="wp-caption alignright" style="width: 360px"><a target="_blank" rel="nofollow" href="http://www.johnbryce.co.il/content/%D7%99%D7%95%D7%9D-%D7%A4%D7%AA%D7%95%D7%97-%D7%90%D7%9C%D7%A7%D7%98%D7%A8%D7%95%D7%A0%D7%99%D7%A7%D7%94/?source=divur_martze"><img alt="Matlab open training day (Israel) - click for details" src="http://undocumentedmatlab.com/courses/Matlab_open_day_350x225b.png" title="Matlab open training day (Israel) - click for details" width="350" height="225"/></a><p class="wp-caption-text">Matlab open training day (Israel) - click for details</p></div></center></p>
<p>Readers in Israel are invited to attend a free training seminar that I will present on advanced Matlab topics in Herzliya, on Thursday April 4, 2013. The seminar is free, but requires registration. <a target="_blank" rel="nofollow" href="http://www.johnbryce.co.il/content/%D7%99%D7%95%D7%9D-%D7%A4%D7%AA%D7%95%D7%97-%D7%90%D7%9C%D7%A7%D7%98%D7%A8%D7%95%D7%A0%D7%99%D7%A7%D7%94/?source=divur_martze">Additional details here</a>. I will speak in Hebrew, but the presentation will be in English and I will be happy to answer questions in English.</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/modifying-matlab-look-and-feel/' rel='bookmark' title='Modifying Matlab&#8217;s Look-and-Feel'>Modifying Matlab&#8217;s Look-and-Feel</a> <small>Matlab's entire Look-and-Feel (PLAF, or L&F) can be modified at the control or application level - this article shows how...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/additional-uicontrol-tooltip-hacks/' rel='bookmark' title='Additional uicontrol tooltip hacks'>Additional uicontrol tooltip hacks</a> <small>Matlab's uicontrol tooltips have several limitations that can be overcome using the control's underlying Java object....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/inactive-control-tooltips-event-chaining/' rel='bookmark' title='Inactive Control Tooltips &amp; Event Chaining'>Inactive Control Tooltips &#038; Event Chaining</a> <small>Inactive Matlab uicontrols cannot normally display their tooltips. This article shows how to do this with a combination of undocumented Matlab and Java hacks....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/setting-line-position-in-edit-box-uicontrol/' rel='bookmark' title='Setting line position in an edit-box uicontrol'>Setting line position in an edit-box uicontrol</a> <small>Matlab uicontrols have many useful features that are only available via Java. Here's how to access them....</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=P5jbuYVKCw8:vBV_w0dHgV0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=P5jbuYVKCw8:vBV_w0dHgV0:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=P5jbuYVKCw8:vBV_w0dHgV0:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=P5jbuYVKCw8:vBV_w0dHgV0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=P5jbuYVKCw8:vBV_w0dHgV0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=P5jbuYVKCw8:vBV_w0dHgV0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=P5jbuYVKCw8:vBV_w0dHgV0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=P5jbuYVKCw8:vBV_w0dHgV0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=P5jbuYVKCw8:vBV_w0dHgV0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=P5jbuYVKCw8:vBV_w0dHgV0:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/P5jbuYVKCw8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/jtattoo-look-and-feel-demo/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/jtattoo-look-and-feel-demo/</feedburner:origLink></item>
		<item>
		<title>HG’s undocumented parameters interface</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/rv1wKZlu8K4/</link>
		<comments>http://undocumentedmatlab.com/blog/hgs-undocumented-parameters-interface/#comments</comments>
		<pubDate>Thu, 14 Mar 2013 14:27:34 +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[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Pure Matlab]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3679</guid>
		<description><![CDATA[Some HG functions also accept inputs parameters in a struct fields rather than the normal P-V pairs format.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/ishghandle-undocumented-input-parameter/' rel='bookmark' title='ishghandle&#8217;s undocumented input parameter'>ishghandle&#8217;s undocumented input parameter</a> <small>The built-in function ishghandle accepts a second input argument with the expected handle type....</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/undocumented-scatter-plot-behavior/' rel='bookmark' title='Undocumented scatter plot behavior'>Undocumented scatter plot behavior</a> <small>The scatter plot function has an undocumented behavior when plotting more than 100 points: it returns a single unified patch object handle, rather than a patch handle for each specific...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/undocumented-scatter-plot-jitter/' rel='bookmark' title='Undocumented scatter plot jitter'>Undocumented scatter plot jitter</a> <small>Matlab's scatter plot can automatically jitter data to enable better visualization of distribution density. ...</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Continuing last week&#8217;s article on Matlab Handle Graphics&#8217; (HG) undocumented Behavior functionality, today I describe another undocumented aspect of HG. Some of the low-level HG functions, such as <i><b>line</b></i> and <i><b>path</b></i> receive their input parameters in one of two formats:</p>
<div class="wp-caption alignright" style="width: 366px"><img alt="HG line created using either of the input formats" src="http://UndocumentedMatlab.com/images/HG_line.gif" title="HG line created using either of the input formats" width="356" height="176"/><p class="wp-caption-text">HG line created using either of the input formats</p></div>
<ul>
<li>The regular fully-documented P-V pairs format:

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">line</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Marker'</span>,<span style="color:#A020F0;">'*'</span>, <span style="color:#A020F0;">'MarkerSize'</span>,<span style="color: #33f;">8</span>, <span style="color:#A020F0;">'MarkerEdgeColor'</span>,<span style="color:#A020F0;">'b'</span>, <span style="color: #F0F;">...</span>
     <span style="color:#A020F0;">'Color'</span>,<span style="color:#A020F0;">'r'</span>, <span style="color:#A020F0;">'XData'</span>,<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">5</span>, <span style="color:#A020F0;">'YData'</span>,<span style="color: #33f;">3</span><span style="color: #F0F;">:</span><span style="color: #33f;">7</span><span style="color: #080;">&#41;</span></pre></div></div>

</li>
<li>An undocumented struct-fields format:

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">lineprops.<span style="">Marker</span> = <span style="color:#A020F0;">'*'</span>;
lineprops.<span style="">MarkerSize</span> = <span style="color: #33f;">15</span>;
lineprops.<span style="">MarkerEdgeColor</span> = <span style="color:#A020F0;">'b'</span>;
lineprops.<span style="">color</span> = <span style="color:#A020F0;">'r'</span>;
lineprops.<span style="">xdata</span> = <span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">5</span>;
lineprops.<span style="">ydata</span> = <span style="color: #33f;">3</span><span style="color: #F0F;">:</span><span style="color: #33f;">7</span>;
&nbsp;
<span style="color: #0000FF;">line</span><span style="color: #080;">&#40;</span>lineprops<span style="color: #080;">&#41;</span></pre></div></div>

</li>
</ul>
<p><span id="more-3679"></span></p>
<p>A sample usage of using the input struct technique can be seen (for example) in <i>%matlabroot%/toolbox/matlab/graphics/@graphics/@datatip/datatip.m</i>. I have also used it in my <a target="_blank" href="http://UndocumentedMatlab.com/ib-matlab/">IB-Marlab</a> application, which connects Matlab to Interactive Brokers. The idea is to make it easy for users to use whichever input format they feel more comfortable with: both P-V pairs or struct fields are supported.</p>
<p>Both input formats can be interchanged and mixed. We should just note that the latest (right-most) property is updated last and overrides any previous value of the same property. Here are some examples &#8212; can you guess the results of each of them?</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">line</span><span style="color: #080;">&#40;</span>lineprops, <span style="color:#A020F0;">'MarkerEdgeColor'</span>,<span style="color:#A020F0;">'g'</span>, <span style="color:#A020F0;">'MarkerSize'</span>,<span style="color: #33f;">7</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">line</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'MarkerEdgeColor'</span>,<span style="color:#A020F0;">'g'</span>, lineprops, <span style="color:#A020F0;">'MarkerSize'</span>,<span style="color: #33f;">7</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">line</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'MarkerEdgeColor'</span>,<span style="color:#A020F0;">'g'</span>, <span style="color:#A020F0;">'MarkerSize'</span>,<span style="color: #33f;">7</span>, lineprops<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">line</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">4</span>, <span style="color: #33f;">2</span><span style="color: #F0F;">:</span><span style="color: #33f;">5</span>, <span style="color:#A020F0;">'MarkerEdgeColor'</span>,<span style="color:#A020F0;">'g'</span>, <span style="color:#A020F0;">'MarkerSize'</span>,<span style="color: #33f;">7</span>, lineprops<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">line</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">4</span>, <span style="color: #33f;">2</span><span style="color: #F0F;">:</span><span style="color: #33f;">5</span>, <span style="color:#A020F0;">'MarkerEdgeColor'</span>,<span style="color:#A020F0;">'g'</span>, lineprops, <span style="color:#A020F0;">'MarkerSize'</span>,<span style="color: #33f;">7</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">line</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">4</span>, <span style="color: #33f;">2</span><span style="color: #F0F;">:</span><span style="color: #33f;">5</span>, lineprops, <span style="color:#A020F0;">'MarkerEdgeColor'</span>,<span style="color:#A020F0;">'g'</span>, <span style="color:#A020F0;">'MarkerSize'</span>,<span style="color: #33f;">7</span><span style="color: #080;">&#41;</span></pre></div></div>

<p>While the struct format is documented (although not widely-used) in the <i><b>set</b></i> function, it is not documented for <i><b>line</b></i>, <i><b>path</b></i> and other functions. Nor is it documented that we can mix the struct format with the P-V pairs format.</p>
<p>Note that not all HG functions support the struct input format. For example, <i><b>line</b></i> does, but <i><b>plot</b></i> does not. I do not understand the reason for this. It would seem reasonable for MathWorks to include this useful struct format for all their HG functions, and since <i><b>set</b></i> already supports it the extra effort would have been trivial. Maybe this will still happen in some future Matlab release&#8230;</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/ishghandle-undocumented-input-parameter/' rel='bookmark' title='ishghandle&#8217;s undocumented input parameter'>ishghandle&#8217;s undocumented input parameter</a> <small>The built-in function ishghandle accepts a second input argument with the expected handle type....</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/undocumented-scatter-plot-behavior/' rel='bookmark' title='Undocumented scatter plot behavior'>Undocumented scatter plot behavior</a> <small>The scatter plot function has an undocumented behavior when plotting more than 100 points: it returns a single unified patch object handle, rather than a patch handle for each specific...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/undocumented-scatter-plot-jitter/' rel='bookmark' title='Undocumented scatter plot jitter'>Undocumented scatter plot jitter</a> <small>Matlab's scatter plot can automatically jitter data to enable better visualization of distribution density. ...</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=rv1wKZlu8K4:9U0sNJeYx0E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=rv1wKZlu8K4:9U0sNJeYx0E:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=rv1wKZlu8K4:9U0sNJeYx0E:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=rv1wKZlu8K4:9U0sNJeYx0E:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=rv1wKZlu8K4:9U0sNJeYx0E:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=rv1wKZlu8K4:9U0sNJeYx0E:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=rv1wKZlu8K4:9U0sNJeYx0E:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=rv1wKZlu8K4:9U0sNJeYx0E:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=rv1wKZlu8K4:9U0sNJeYx0E:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=rv1wKZlu8K4:9U0sNJeYx0E:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/rv1wKZlu8K4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/hgs-undocumented-parameters-interface/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/hgs-undocumented-parameters-interface/</feedburner:origLink></item>
		<item>
		<title>Handle Graphics Behavior</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/te89VduaqpE/</link>
		<comments>http://undocumentedmatlab.com/blog/handle-graphics-behavior/#comments</comments>
		<pubDate>Wed, 06 Mar 2013 18:00:19 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Semi-documented function]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[schema]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3665</guid>
		<description><![CDATA[HG behaviors are an important aspect of Matlab graphics that enable custom control of handle functionality.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/undocumented-scatter-plot-behavior/' rel='bookmark' title='Undocumented scatter plot behavior'>Undocumented scatter plot behavior</a> <small>The scatter plot function has an undocumented behavior when plotting more than 100 points: it returns a single unified patch object handle, rather than a patch handle for each specific...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/' rel='bookmark' title='Displaying hidden handle properties'>Displaying hidden handle properties</a> <small>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/waterloo-graphics/' rel='bookmark' title='Waterloo graphics'>Waterloo graphics</a> <small>Waterloo is an open-source library that can significantly improve Matlab GUI. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/waterloo-graphics-examples/' rel='bookmark' title='Waterloo graphics examples'>Waterloo graphics examples</a> <small>Some Matlab usage examples for the open-source Waterloo graphics package. ...</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Matlab&#8217;s Handle Graphics (HG) have been around for ages. Still, to this day it contains many hidden gems. Today I discuss HG&#8217;s <b>Behavior</b> property, which is a standard <a target="_blank" href="http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/">undocumented hidden property</a> of all HG objects. </p>
<p><b>Behavior</b> is not normally updated directly (although there is absolutely nothing to prevent this), but rather via the <a target="_blank" href="http://undocumentedmatlab.com/blog/legend-semi-documented-feature/#Semi-documented">semi-documented</a> built-in accessor functions <i><b>hggetbehavior</b></i> and <i><b>hgaddbehavior</b></i>. This manner of accessing <b>Behavior</b> is similar to its undocumented sibling property <b>ApplicationData</b>, which is accessed by the corresponding <i><b>getappdata</b></i> and <i><b>setappdata</b></i> functions.</p>
<h3 id="usage">Using HB behaviors</h3>
<p><i><b>hggetbehavior</b></i> with no input args displays a list of all pre-installed HG behaviors:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; hggetbehavior
&nbsp;
   Behavior Object Name         Target Handle
   --------------------------------------------
   <span style="color:#A020F0;">'Plotedit'</span><span style="color: #F0F;">..................</span>.<span style="color: #0000FF;">Any</span> Graphics Object   
   <span style="color:#A020F0;">'Print'</span><span style="color: #F0F;">.....................</span>.<span style="color: #0000FF;">Any</span> Graphics Object   
   <span style="color:#A020F0;">'Zoom'</span><span style="color: #F0F;">.....................</span>..<span style="color: #0000FF;">Axes</span>                  
   <span style="color:#A020F0;">'Pan'</span><span style="color: #F0F;">........................</span><span style="color: #0000FF;">Axes</span>                  
   <span style="color:#A020F0;">'Rotate3d'</span><span style="color: #F0F;">..................</span>.<span style="color: #0000FF;">Axes</span>                  
   <span style="color:#A020F0;">'DataCursor'</span><span style="color: #F0F;">...............</span>..<span style="color: #0000FF;">Axes</span> and <span style="color: #0000FF;">Axes</span> Children
   <span style="color:#A020F0;">'MCodeGeneration'</span><span style="color: #F0F;">............</span><span style="color: #0000FF;">Axes</span> and <span style="color: #0000FF;">Axes</span> Children
   <span style="color:#A020F0;">'DataDescriptor'</span><span style="color: #F0F;">............</span>.<span style="color: #0000FF;">Axes</span> and <span style="color: #0000FF;">Axes</span> Children
   <span style="color:#A020F0;">'PlotTools'</span><span style="color: #F0F;">..................</span><span style="color: #0000FF;">Any</span> graphics object   
   <span style="color:#A020F0;">'Linked'</span><span style="color: #F0F;">.....................</span><span style="color: #0000FF;">Any</span> graphics object   
   <span style="color:#A020F0;">'Brush'</span><span style="color: #F0F;">.....................</span>.<span style="color: #0000FF;">Any</span> graphics object</pre></div></div>

<p><span id="more-3665"></span></p>
<p><i><b>hggetbehavior</b></i> can be passed a specific behavior name (or cell array of names), in which case it returns the relevant behavior object handle(s):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; hBehavior = hggetbehavior<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>, <span style="color:#A020F0;">'Zoom'</span><span style="color: #080;">&#41;</span>
hBehavior =
	graphics.<span style="">zoombehavior</span>
&nbsp;
&gt;&gt; hBehavior = hggetbehavior<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>, <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'Zoom'</span>, <span style="color:#A020F0;">'Pan'</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>
hBehavior =
	handle<span style="color: #F0F;">:</span> <span style="color: #33f;">1</span>-by-<span style="color: #33f;">2</span></pre></div></div>

<p>As the name indicates, the behavior object handle controls the behavior of the relevant action. For example, the behavior object for Zoom contains the following properties:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; hBehavior = hggetbehavior<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>, <span style="color:#A020F0;">'Zoom'</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hBehavior<span style="color: #080;">&#41;</span>
       Enable<span style="color: #F0F;">:</span> <span style="color: #33f;">1</span>        <span style="color: #228B22;">% settable: true/false</span>
    Serialize<span style="color: #F0F;">:</span> <span style="color: #33f;">1</span>        <span style="color: #228B22;">% settable: true/false</span>
         Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'Zoom'</span>   <span style="color: #228B22;">% read-only</span>
        Style<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'both'</span>   <span style="color: #228B22;">% settable: 'horizontal', 'vertical' or 'both'</span></pre></div></div>

<p>By setting the behavior&#8217;s properties, we can control whether the axes will have horizontal, vertical, 2D or no zooming enabled, regardless of whether or not the toolbar/menu-bar zoom item is selected:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hBehavior.<span style="">Enable</span> = <span style="color: #0000FF;">false</span>;         <span style="color: #228B22;">% or: set(hBehavior,'Enable',false)</span>
hBehavior.<span style="">Style</span>  = <span style="color:#A020F0;">'horizontal'</span>;  <span style="color: #228B22;">% or: set(hBehavior,'Style','horizontal')</span></pre></div></div>

<p>This mechanism is used internally by Matlab to disable zoom/pan/rotate3d (see <i>%matlabroot%/toolbox/matlab/graphics/@graphics/@zoom/setAllowAxesZoom.m</i> and similarly <i>setAllowAxesPan, setAllowAxesRotate</i>).</p>
<p>At this point, some readers may jump saying that we can already do this via the zoom object handle that is returned by the <i><b>zoom</b></i> function (where the <b>Style</b> property was renamed <b>Motion</b>, but never mind). However, I am just trying to show the general usage. Not all behaviors have similar documented customizable mechanisms. In fact, using behaviors we can control specific behaviors for separate HG handles in the same figure/axes.</p>
<p>For example, we can set a different callback function to different HG handles for displaying a plot data-tip (a.k.a. data cursor). I have explained in the past how to <a target="_blank" href="http://undocumentedmatlab.com/blog/controlling-plot-data-tips/">programmatically control data-tips</a>, but doing so relies on the figure <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/ref/datacursormode.html"><i><b>datacursormode</b></i></a>, which is figure-wide. If we want to display different data-tips for different plot handles, we would need to add logic into our custom update function that would change the returned string based on the clicked handle. Using HG behavior we can achieve the same goal much easier:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Use dataCursorLineFcn() for the line data-tip</span>
bh = hggetbehavior<span style="color: #080;">&#40;</span>hLine,<span style="color:#A020F0;">'DataCursor'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>bh,<span style="color:#A020F0;">'UpdateFcn'</span>,<span style="color: #F0F;">@</span>dataCursorLineFcn<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Use dataCursorAnnotationFcn() for the annotation data-tip</span>
bh = hggetbehavior<span style="color: #080;">&#40;</span>hAnnotation,<span style="color:#A020F0;">'DataCursor'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>bh,<span style="color:#A020F0;">'UpdateFcn'</span>,<span style="color: #080;">&#123;</span><span style="color: #F0F;">@</span>dataCursorAnnotationFcn,extraData<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Note: there is also the related semi-documented function <i><b>hgbehaviorfactory</b></i>, which is used internally by <i><b>hggetbehavior</b></i> and <i><b>hgaddbehavior</b></i>. I do not see any need for using <i><b>hgbehaviorfactory</b></i> directly, only <i><b>hggetbehavior</b></i> and <i><b>hgaddbehavior</b></i>.</p>
<h3 id="custom">Custom behaviors</h3>
<p>The standard behavior objects are UDD schema objects (i.e., the old object-oriented mechanism in MATLAB). They are generally located in a separate folder beneath <i>%matlabroot%/toolbox/matlab/graphics/@graphics/</i>. For example, the Zoom behavior object is located in <i>%matlabroot%/toolbox/matlab/graphics/@graphics/@zoombehavior/</i>. These behavior object folders generally contain a <i>schema.m</i> file (that defines the behavior object class and its properties), and a <i>dosupport.m</i> function that returns a logical flag indicating whether or not the behavior is supported for the specified handle. These are pretty standard functions, here is an example:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Zoom behavior's schema.m:</span>
<span style="color: #0000FF;">function</span> schema
<span style="color: #228B22;">% Copyright 2003-2006 The MathWorks, Inc.</span>
&nbsp;
pk = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'graphics'</span><span style="color: #080;">&#41;</span>;
cls = schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#40;</span>pk,<span style="color:#A020F0;">'zoombehavior'</span><span style="color: #080;">&#41;</span>;
&nbsp;
p = schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'Enable'</span>,<span style="color:#A020F0;">'bool'</span><span style="color: #080;">&#41;</span>;
p.<span style="">FactoryValue</span> = <span style="color: #0000FF;">true</span>;
&nbsp;
p = schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'Serialize'</span>,<span style="color:#A020F0;">'MATLAB array'</span><span style="color: #080;">&#41;</span>;
p.<span style="">FactoryValue</span> = <span style="color: #0000FF;">true</span>;
p.<span style="">AccessFlags</span>.<span style="">Serialize</span> = <span style="color:#A020F0;">'off'</span>;
&nbsp;
p = schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'Name'</span>,<span style="color:#A020F0;">'string'</span><span style="color: #080;">&#41;</span>;
p.<span style="">AccessFlags</span>.<span style="">PublicSet</span> = <span style="color:#A020F0;">'off'</span>;
p.<span style="">AccessFlags</span>.<span style="">PublicGet</span> = <span style="color:#A020F0;">'on'</span>;
p.<span style="">FactoryValue</span> = <span style="color:#A020F0;">'Zoom'</span>;
p.<span style="">AccessFlags</span>.<span style="">Serialize</span> = <span style="color:#A020F0;">'off'</span>;
&nbsp;
<span style="color: #228B22;">% Enumeration Style Type</span>
<span style="color: #0000FF;">if</span> <span style="color: #080;">&#40;</span><span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>findtype<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'StyleChoice'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
    schema.<span style="">EnumType</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'StyleChoice'</span>,<span style="color: #080;">&#123;</span><span style="color:#A020F0;">'horizontal'</span>,<span style="color:#A020F0;">'vertical'</span>,<span style="color:#A020F0;">'both'</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
p = schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'Style'</span>,<span style="color:#A020F0;">'StyleChoice'</span><span style="color: #080;">&#41;</span>;
p.<span style="">FactoryValue</span> = <span style="color:#A020F0;">'both'</span>;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Zoom behavior's dosupport.m:</span>
<span style="color: #0000FF;">function</span> <span style="color: #080;">&#91;</span>ret<span style="color: #080;">&#93;</span> = dosupport<span style="color: #080;">&#40;</span>~,hTarget<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">% Copyright 2003-2009 The MathWorks, Inc.</span>
&nbsp;
<span style="color: #228B22;">% axes </span>
ret = ishghandle<span style="color: #080;">&#40;</span>hTarget,<span style="color:#A020F0;">'axes'</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>All behaviors must define the <b>Name</b> property, and most behaviors also define the <b>Serialize</b> and <b>Enable</b> properties. In addition, different behaviors define other properties. For example, the DataCursor behavior defines the <b>CreateNewDatatip</b> flag and no less than 7 callbacks:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> schema
<span style="color: #228B22;">% Copyright 2003-2008 The MathWorks, Inc.</span>
&nbsp;
pk = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'graphics'</span><span style="color: #080;">&#41;</span>;
cls = schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#40;</span>pk,<span style="color:#A020F0;">'datacursorbehavior'</span><span style="color: #080;">&#41;</span>;
&nbsp;
p = schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'Name'</span>,<span style="color:#A020F0;">'string'</span><span style="color: #080;">&#41;</span>;
p.<span style="">AccessFlags</span>.<span style="">PublicSet</span> = <span style="color:#A020F0;">'off'</span>;
p.<span style="">AccessFlags</span>.<span style="">PublicGet</span> = <span style="color:#A020F0;">'on'</span>;
p.<span style="">FactoryValue</span> = <span style="color:#A020F0;">'DataCursor'</span>;
&nbsp;
schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'StartDragFcn'</span>,<span style="color:#A020F0;">'MATLAB callback'</span><span style="color: #080;">&#41;</span>;
schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'EndDragFcn'</span>,<span style="color:#A020F0;">'MATLAB callback'</span><span style="color: #080;">&#41;</span>;
schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'UpdateFcn'</span>,<span style="color:#A020F0;">'MATLAB callback'</span><span style="color: #080;">&#41;</span>;
schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'CreateFcn'</span>,<span style="color:#A020F0;">'MATLAB callback'</span><span style="color: #080;">&#41;</span>;
schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'StartCreateFcn'</span>,<span style="color:#A020F0;">'MATLAB callback'</span><span style="color: #080;">&#41;</span>;
schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'UpdateDataCursorFcn'</span>,<span style="color:#A020F0;">'MATLAB callback'</span><span style="color: #080;">&#41;</span>;
schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'MoveDataCursorFcn'</span>,<span style="color:#A020F0;">'MATLAB callback'</span><span style="color: #080;">&#41;</span>;
&nbsp;
p = schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'CreateNewDatatip'</span>,<span style="color:#A020F0;">'bool'</span><span style="color: #080;">&#41;</span>;
p.<span style="">FactoryValue</span> = <span style="color: #0000FF;">false</span>;
p.<span style="">Description</span> = <span style="color:#A020F0;">'True will create a new datatip for every mouse click'</span>;
p = schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'Enable'</span>,<span style="color:#A020F0;">'bool'</span><span style="color: #080;">&#41;</span>;
p.<span style="">FactoryValue</span> = <span style="color: #0000FF;">true</span>;
&nbsp;
p = schema.<span style="">prop</span><span style="color: #080;">&#40;</span>cls,<span style="color:#A020F0;">'Serialize'</span>,<span style="color:#A020F0;">'MATLAB array'</span><span style="color: #080;">&#41;</span>;
p.<span style="">FactoryValue</span> = <span style="color: #0000FF;">true</span>;
p.<span style="">AccessFlags</span>.<span style="">Serialize</span> = <span style="color:#A020F0;">'off'</span>;</pre></div></div>

<p>Why am I telling you all this? Because in addition to the standard behavior objects we can also specify custom behaviors to HG handles. All we need to do is mimic one of the standard behavior object classes in a user-defined class, and then use <i><b>hgaddbehavior</b></i> to add the behavior to an HG handle. Behaviors are differentiated by their <b>Name</b> property, so we can either use a new name for the new behavior, or override a standard behavior by reusing its name.</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hgaddbehavior<span style="color: #080;">&#40;</span>hLine,myNewBehaviorObject<span style="color: #080;">&#41;</span></pre></div></div>

<p>If you wish the behavior to be serialized (saved) to disk when saving the figure, you should add the <b>Serialize</b> property to the class and set it to <code>true</code>, then use <i><b>hgaddbehavior</b></i> to add the behavior to the relevant HG handle. The <b>Serialize</b> property is searched-for by the <i><b>hgsaveStructDbl</b></i> function when saving figures (I described <i><b>hgsaveStructDbl</b></i> <a target="_blank" href="http://undocumentedmatlab.com/blog/handle2struct-struct2handle-and-matlab-8/">here</a>). All the standard behaviors except DataDescriptor have the <b>Serialize</b> property (I don&#8217;t know why DataDescriptor doesn&#8217;t).</p>
<p>Just for the record, you can also use MCOS (not just UDD) class objects for the custom behavior, as mentioned by the internal comment within the <i><b>hgbehaviorfactory</b></i> function. Most standard behaviors use UDD schema classes; an example of an MCOS behavior is PlotEdit that is found at <i>%matlabroot%/toolbox/matlab/graphics/+graphics/+internal/@PlotEditBehavor/PlotEditBehavor.m</i>.</p>
<h3 id="ishghandle"><i>ishghandle</i>&#8216;s undocumented type input arg</h3>
<p>Note that the Zoom behavior&#8217;s <i>dosupport</i> function uses an undocumented format of the built-in <i><b>ishghandle</b></i> function, namely accepting a second parameter that specifies a specific handle type, which presumably needs to correspond to the handle&#8217;s <b>Type</b> property:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">ret = ishghandle<span style="color: #080;">&#40;</span>hTarget,<span style="color:#A020F0;">'axes'</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<h3 id="hasbehavior">The <i>hasbehavior</i> function</h3>
<p>Another semi-documented built-in function called <i><b>hasbehavior</b></i> is located right next to <i><b>hggetbehavior</b></i> and <i><b>hgaddbehavior</b></i> in the <i>%matlabroot%/toolbox/matlab/graphics/</i> folder. </p>
<p>Despite its name, and the internal comments that specifically mention HG behaviors, this function is entirely independent of the HG behavior mechanism described above, and in fact makes use of the <b>ApplicationData</b> property rather than <b>Behavior</b>. I have no idea why this is so. It may be a design oversight or some half-baked attempt by a Mathworker apprentice to emulate the behavior mechanism. Even the function name is misleading: in fact, <i><b>hasbehavior</b></i> not only checks whether a handle has some &#8220;behavior&#8221; (in the 2-input args format) but also sets this flag (in the 3-input args format).</p>
<p><i><b>hasbehavior</b></i> is used internally by the legend mechanism, to determine whether or not an HG object (line, scatter group, patch, annotation etc.) should be added to the legend. This can be very important for <a target="_blank" href="http://undocumentedmatlab.com/blog/plot-performance/#Legend">plot performance</a>, since the legend would not need to be updated whenever these objects are modified in some manner:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hLines = <span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">rand</span><span style="color: #080;">&#40;</span><span style="color: #33f;">3</span>,<span style="color: #33f;">3</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
hasbehavior<span style="color: #080;">&#40;</span>hLines<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>, <span style="color:#A020F0;">'legend'</span>, <span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% line will not be in legend</span>
hasbehavior<span style="color: #080;">&#40;</span>hLines<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>, <span style="color:#A020F0;">'legend'</span>, <span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;    <span style="color: #228B22;">% line will be in legend</span></pre></div></div>

<p>(for anyone interested, the relevant code that checks this flag is located in <i>%matlabroot%/toolbox/matlab/scribe/private/islegendable.m</i>)</p>
<p><i><b>hasbehavior</b></i> works by using a dedicated field in the handle&#8217;s <b>ApplicationData</b> struct with a logical flag value (<code>true/false</code>). The relevant field is called <code>[name,'_hgbehavior']</code>, where <code>name</code> is the name of the so-called &#8220;behavior&#8221;. In the example above, it creates a field called &#8220;legend_hgbehavior&#8221;.</p>
<p>Do you know of any neat uses for HG behaviors? If so, please post a comment <a href="http://undocumentedmatlab.com/blog/handle-graphics-behavior/#respond">below</a>.</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/undocumented-scatter-plot-behavior/' rel='bookmark' title='Undocumented scatter plot behavior'>Undocumented scatter plot behavior</a> <small>The scatter plot function has an undocumented behavior when plotting more than 100 points: it returns a single unified patch object handle, rather than a patch handle for each specific...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/' rel='bookmark' title='Displaying hidden handle properties'>Displaying hidden handle properties</a> <small>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/waterloo-graphics/' rel='bookmark' title='Waterloo graphics'>Waterloo graphics</a> <small>Waterloo is an open-source library that can significantly improve Matlab GUI. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/waterloo-graphics-examples/' rel='bookmark' title='Waterloo graphics examples'>Waterloo graphics examples</a> <small>Some Matlab usage examples for the open-source Waterloo graphics package. ...</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=te89VduaqpE:yz1Omi-A4Zw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=te89VduaqpE:yz1Omi-A4Zw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=te89VduaqpE:yz1Omi-A4Zw:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=te89VduaqpE:yz1Omi-A4Zw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=te89VduaqpE:yz1Omi-A4Zw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=te89VduaqpE:yz1Omi-A4Zw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=te89VduaqpE:yz1Omi-A4Zw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=te89VduaqpE:yz1Omi-A4Zw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=te89VduaqpE:yz1Omi-A4Zw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=te89VduaqpE:yz1Omi-A4Zw:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/te89VduaqpE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/handle-graphics-behavior/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/handle-graphics-behavior/</feedburner:origLink></item>
		<item>
		<title>Matclipse – Eclipse-Matlab interface</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/BJ320yMfbnQ/</link>
		<comments>http://undocumentedmatlab.com/blog/matclipse-eclipse-matlab-interface/#comments</comments>
		<pubDate>Wed, 27 Feb 2013 18:00:07 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Christopher Albert]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3647</guid>
		<description><![CDATA[Matclipse is an open-source plugin for the popular Eclipse IDE that connects it with Matlab.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/jmi-java-to-matlab-interface/' rel='bookmark' title='JMI &#8211; Java-to-Matlab Interface'>JMI &#8211; Java-to-Matlab Interface</a> <small>JMI enables calling Matlab functions from within Java. This article explains JMI's core functionality....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/matlab-java-interface-using-static-control/' rel='bookmark' title='Matlab-Java interface using a static control'>Matlab-Java interface using a static control</a> <small>The switchyard function design pattern can be very useful when setting Matlab callbacks to Java GUI controls. This article explains why and how....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/using-groovy-in-matlab/' rel='bookmark' title='Using Groovy in Matlab'>Using Groovy in Matlab</a> <small>Groovy code can seamlessly be run from within Matlab. ...</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>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p><i>I am extremely pleased to host guest blogger Christopher Albert. Chris and his colleagues created and maintain the enormously-interesting (IMHO) and complex Matclipse project, which connects Java&#8217;s popular Eclipse IDE with Matlab.</i></p>
<p>The open-source <i><b>matclipse</b></i> project is an interface between the Java integrated development environment (IDE) <a target="_blank" rel="nofollow" href="http://www.eclipse.org">Eclipse</a> and Matlab. It was developed at the <a target="_blank" rel="nofollow" href="http://itp.tugraz.at/">Institute for Theoretical and Computational Physics</a> (ITP) at <a target="_blank" rel="nofollow" href="http://www.tugraz.at">Graz University of Technology</a> (TU Graz) by a team that consisted of David Camhy, Winfried Kernbichler, Georg Huhs and Christopher Albert. <i><b>Matclipse</b></i> is part of a bigger endeavor, namely, the development of the teaching and learning environment <a target="_blank" rel="nofollow" href="http://itp.tu-graz.ac.at/wiki/index.php/MLTutor_Konzept">MatlabTutor</a>. It is released under the <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Eclipse_Public_License">Eclipse Public License</a> (<a target="_blank" rel="nofollow" href="http://www.eclipse.org/legal/epl-v10.html">full text</a>).</p>
<p>The aim of the project is to facilitate the usage of Matlab directly from Eclipse under various operating systems (Linux, Windows, OS X). At the moment, it consists of a workbench, an Matlab editor, a Matlab console including a command window and a viewer for results, a Matlab command history and a Matlab workspace viewer.</p>
<p>The <i><b>matclipse</b></i> project is <a target="_blank" rel="nofollow" href="http://code.google.com/a/eclipselabs.org/p/matclipse/">hosted</a> on Google Code. Unfortunately, it does not contain a lot of external documentation, except a somewhat-outdated <a target="_blank" rel="nofollow" href="http://code.google.com/a/eclipselabs.org/p/matclipse/w/list">wiki</a>, with <a target="_blank" rel="nofollow" href="http://code.google.com/a/eclipselabs.org/p/matclipse/wiki/Installation">installation instructions</a>. A list of open issues is maintained <a target="_blank" rel="nofollow" href="http://code.google.com/a/eclipselabs.org/p/matclipse/issues/list">here</a>, where you can also report new issues. There is also a <a target="_blank" rel="nofollow" href="http://groups.google.com/group/matclipse">newsgroup forum/mailing-list</a> with some activity.</p>
<h3 id="Workbench">Matlab Workbench</h3>
<p>The Matlab workbench uses a tree structure for workspace. One can create Matlab projects there and, of course, all basic features from Eclipse are supported there. Projects can have a Matlab nature and files can be executed directly from the workbench without opening them in the editor.</p>
<p><center><div class="wp-caption aligncenter" style="width: 460px"><a target="_blank" href="http://UndocumentedMatlab.com/images/matclipse_workbench.gif"><img alt="The matclipse workbench within Eclipse (click for details)" src="http://UndocumentedMatlab.com/images/matclipse_workbench_sml.gif" title="The matclipse workbench within Eclipse (click for details)" width="450" height="384"/></a><p class="wp-caption-text">The matclipse workbench within Eclipse (click for details)</p></div></center><br />
<span id="more-3647"></span></p>
<h3 id="Communication">Communication with Matlab</h3>
<p>At the moment, the communication between Java and Matlab is based on the usage of pipes under Linux and OS X and on the usage of DCOM under Windows. In both cases it is necessary to have a local installation of Matlab. An extension to enable communication with a remote Matlab server is planned for the future but various issues (see below) have to resolved for a successful implementation of this feature.</p>
<p>In Linux as well as OS X there is no documented way of access to Matlab, to its memory and to its variables. For that reason, the most reliable way of communication was the usage of pipes. Since in this case, memory in Matlab and memory in Eclipse is strictly separated, any transfer of variables from Matlab to Eclipse needs time and doubles the amount of necessary memory. Therefore, this is not the best of all ways but without the help of MathWorks no other possibility is feasible. Under the operating system Windows, MathWorks provides DCOM as a possibility to control Matlab.</p>
<p>With pipes a remote access to Matlab on a remote Linux server is possible because pipes can be established through a ssh-tunnel. In addition, a remote file system from this server has to be mounted in Eclipse. A good candidate for this seems to be a ssh-based file system. This would enable the storage of programs directly from the editor on the server where Matlab could execute them.</p>
<p>Additional problems arises if graphical output is produced in Matlab or if Matlab tools like the help browser or the profile viewer has to be used. One way to handle this problem is the installation of an X11 server on the client which could display all additional windows from the server on the client through the X11 protocol in case of a correct setting of the display variable. Beside issues of security and speed, technically everything could run as on a local machine but the requirement is a reliable X11server used by Eclipse on the client side.</p>
<p>Another possibility to use a remote server is the conversion of Matlab figures to pictures (e.g. PNG) and to transfer those pictures through the pipe back to the client. The task of eclipse then would be to provide a viewer for this pictures. Of course, any interaction with the figures in a Matlab kind of way (zooming in and out, rotation, etc.) would not be possible. It would also require some overhead to detect what figures are new or have been modified to keep the time for transfer as low as possible. Also bookkeeping for figures has to be established to be able to remove deleted figures from the picture viewer. With the restrictions mentioned above this is possible. A usage of the help browser and profile viewer would not be possible in this case. Ideally, the user could have a choice between both methods.</p>
<h3 id="Editor">Matlab Editor</h3>
<p><div class="wp-caption alignright" style="width: 356px"><img alt="Matclipse's Matlab editor" src="http://UndocumentedMatlab.com/images/matclipse_editor.gif" title="Matclipse's Matlab editor" width="346" height="405"/><p class="wp-caption-text">Matclipse's Matlab editor</p></div>The Matlab editor is based on a regular expression parser which provides syntax highlighting and checking. A new Xtext-based version had been under development but was not been brought to a usable state due to the limitations of the features and performance of the Xtext framework.</p>
<p>The current features are:</p>
<ul>
<li>Smart indentation and parenthesis matching.</li>
<li>Detection of variables, operators, strings, commands and key words.</li>
<li>Integration of the Matlab program mlint to mark errors and warnings directly in the editor.</li>
</ul>
<p>Possible improvements for the future could be:</p>
<ul>
<li>Syntax highlighting with detection of all Matlab commands also from available toolboxes. The list of these commands has to be extracted from the Matlab help directory for a given version of Matlab. Commands from Matlab directly and from toolboxes can be shown in different colors.</li>
<li>Direct link to Matlab help pages locally or situated at MathWorks.</li>
<li>Evaluation of the whole file or of a selection of lines directly in Matlab.</li>
<li>Export of a documented file in XML, Latex, PDF or HTML format. With syntax highlighting, indentation and links to Matlab help.</li>
<li>Usage of a simple wiki-like markup language to display mathematical formulas, lists</li>
</ul>
<h3 id="Console">Matlab Console</h3>
<p><div class="wp-caption alignright" style="width: 322px"><img alt="Matclipse's Matlab console" src="http://UndocumentedMatlab.com/images/matclipse_console.gif" title="Matclipse's Matlab console" width="312" height="275"/><p class="wp-caption-text">Matclipse's Matlab console</p></div>In contrast to Matlab where input to and output from Matlab is displayed in the same window, <i><b>matclipse</b></i> uses a concept with a separate command line for input to Matlab and a results viewer for displaying the output from Matlab nicely separated by the input commands. This concept proved to be practical but has its limitations.</p>
<p>The current features of the command line are the following:</p>
<ul>
<li>Syntax highlighting is provided by the editor.</li>
<li>Up- and down-scrolling in the command history.</li>
<li>The Matlab command input had to be overwritten with a version which opens an input dialog box (<i><b>inputdlg</b></i>) in a modal Matlab window. There was no other way to enable the user to provide the input to Matlab. This is a clear disadvantage when using a remote server because this solution for sure requires a X11 server to display the modal window.</li>
<li>The Matlab command pause without an additional time specified had to be overwritten. It is terminated now automatically after 2 seconds because there was no way to terminate the pause from the command line. In future one would have to think of an icon (or a shortcut) which would terminate the pause in similar way as CTRL-C is handled to stop execution of a command.</li>
<li>CTRL-C does not work in the command line. An icon was provided in the console to stop execution of Matlab.</li>
<li>Icons are provided to start and stop Matlab.</li>
<li>Additional icons are available to bring figures in the foreground or to delete figures.</li>
<li>There is a possibility to change the Matlab directory without a Matlab command.</li>
<li>One can start the Matlab help browser from an icon.</li>
<li>One can clear the results view from an icon (<i><b>clc</b></i> does not work).</li>
<li>One can toggle Matlab console debug from an icon, to debug the XML communication between <i><b>matclipse</b></i> and Matlab. Note that this debug mode does not enable debugging the Matlab code itself &#8211; perhaps this will be added in the future.</li>
</ul>
<p>Additional disadvantages and plans for the future are summarized here.</p>
<ul>
<li>When scrolling up or down the lines with %- should not be shown in the command line.</li>
<li>When scrolling up or down one should be able to write some letters before starting to scroll. In this case one should get only a limited choice. E.g., if one writes <i>plo</i> one should only get command lines from history which start with these letters, like <i><b>plot</b>(x,y)</i>.</li>
<li>This feature could be extended to allow for wildcards. E.g., if one writes <i>*sin</i> one should get only lines which contain <i>sin</i> at some position.</li>
<li>Copy and Paste should be enabled with shortcuts everywhere. At the moment one needs the context menu for this.</li>
<li>One should cycle round when reaching the end or the beginning of the command history.</li>
<li>The Matlab command <i><b>clc</b></i> should be parsed and it should not be send to Matlab. Instead, the results view should be cleared.</li>
<li>The Matlab command <i><b>edit</b></i> or <i><b>edit</b>(filename)</i> should be parsed and it should not be send to Matlab. Instead, one should be placed in the correct editor window. If the <i>filename</i> does not exist, it should be created. If the Matlab extension <i>*.m</i> does not exist it should be added automatically.</li>
<li>In addition to the icon for the Matlab help browser there should be an icon for the Matlab profile viewer.</li>
<li>A debug mode should be enabled. This would require an integration of the editor into this task.</li>
<li>At the moment, the workspace viewer is updated after each execution of the command line. This results in a time delay which gets bigger when there is a larger Matlab workspace. This update should only happen when the user switches to the tab with the workspace view. Otherwise, if the workspace view is not used, unnecessary time is wasted with the update.</li>
<li>Sometimes there is the problem that Matlab is busy when the user tries to execute a script. This might be in connection with the use of <i><b>mlint</b></i> directly from the editor. The context menu Save and Run forces saving of the file which triggers mlint and then tries to execute the script. Maybe one has to wait until mlint is finished or it should be clearly shown to the user that the script could not be executed. Now this is sometimes confusing.</li>
</ul>
<h3 id="History">Matlab Command History</h3>
<p><div class="wp-caption alignright" style="width: 190px"><img alt="Matclipse's Matlab command history" src="http://UndocumentedMatlab.com/images/matclipse_history.gif" title="Matclipse's Matlab command history" width="180" height="231"/><p class="wp-caption-text">Matclipse's Matlab command history</p></div>The Matlab history records commands which are executed for further usage. The data are stored in sections with different starting times of a working session. In contrast to Matlab, lines which are used again without any change are not duplicated but moved to the current location. This keeps the list shorter.</p>
<p>In case a couple of lines are executed from the editor with <code>execute selection</code>, those lines a stored in one entry in the command history and can be recalled at once.</p>
<p>Additional features and fixes are recorded here:</p>
<ul>
<li>A selection of more than one line should be possible for execution, deleting and copying.</li>
<li>Add <code>delete old</code> to the context menu to erase all entries from previous sessions.</li>
<li>When there are more commands in one line, one should not show the <code>\n</code>, one should rather use a space instead for the display and keep it for execution. This is only cosmetics because it just looks ugly.</li>
<li>Drag and drop to the command window is not really necessary because there exist faster ways with scrolling and the return key.</li>
<li>The user should be able to collapse selections or everything belonging to some old session. Those things should be stored but not used when scrolling up or down in the command line.</li>
</ul>
<h3 id="Workspace">Matlab Workspace Viewer</h3>
<p><div class="wp-caption alignright" style="width: 390px"><img alt="Matclipse's Matlab workspace browser" src="http://UndocumentedMatlab.com/images/matclipse_workspace.gif" title="Matclipse's Matlab workspace browser" width="380" height="240"/><p class="wp-caption-text">Matclipse's Matlab workspace browser</p></div>The Matlab workspace viewer enables the user to explore the Matlab variables. In contrast to Matlab, a tree is used for this view where all data types can be displayed. So called container data types like cells and structures are displayed with there size and then a sub-tree is opened which shows the contents in the container. This is possible for the whole depths of those data types. To save time especially when working with pipes, first only the structure of the workspace is shown in the tree together with size information. The detailed information about the content of an array is only transferred from Matlab to Eclipse when this entry is chosen with the mouse or the keyboard.</p>
<p>To avoid unnecessary transfer of data only a limited amount of data from a big array is requested from Matlab. The selection shows relevant information in a compressed form but never shows 100 x 100 array fully. Typically it shows a first block of data from the array accompanied by the last row and the last line to give a good and compact view on the data.</p>
<p>The exchange of information between Matlab and Eclipse is based on a XML description of the workspace generated within Matlab.</p>
<p>Additional features and fixes are recorded here:</p>
<ul>
<li>In addition to class, name and size one could show for numerical arrays the minimum and the maximum as well as the mean value to have a better overview. The appropriate Matlab routines are already modified to provide those information in the XML representation.</li>
<li>To be able to view the whole content of a numeric data type one could add a context menu which then would transfer all data for this array for display in a style sheet like viewer.</li>
<li>In the context menu (and with the delete button) one should be able to delete variables. This should be possible only on the first level. So specific content of cells and structures can not be deleted in such a way.</li>
<li>When selecting one or more variables, it should be possible to edit a plot command which should then be send to Matlab. E.g., if you select the variables x and y then the context menu should open a small editor window with pre-filled commands like <i><b>figure; plot</b>(x,y)</i>. If the user does not like the choice then he can edit this field and finally the command is send to Matlab. There is no need to transfer the data to Eclipse.</li>
<li>One could imagine a similar feature when selecting two numerical arrays for comparison. For this a Matlab routine could be provided to display the differences and similarities.</li>
</ul>
<h3 id="Eigenvector">Multivariate analysis with Eigenvector</h3>
<p><i>(the following is once again in my (Yair&#8217;s) own voice):</i></p>
<p>I would like to direct readers attention to Eigenvector Research (featured as a sidebar ad on this page). Eigenvector provides Matlab-based solutions for multivariate analysis (MVA) with a specific emphasis on chemical applications, i.e. chemometrics. Their products include the <a target="_blank" rel="nofollow" href="http://www.eigenvector.com/software/pls_toolbox.htm?undoc">PLS_Toolbox</a> for general MVA/chemometrics, and <a target="_blank" rel="nofollow" href="http://www.eigenvector.com/software/mia_toolbox.htm?undoc">MIA_Toolbox</a> for Multivariate Image Analysis. They also provide <a target="_blank" rel="nofollow" href="http://www.eigenvector.com/training.htm?undoc">training</a> and <a target="_blank" rel="nofollow" href="http://www.eigenvector.com/consult.html?undoc">consulting</a> services.</p>
<p>If you work with applications that produce large amounts of multivariate data, you may well find their products and services useful.</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/jmi-java-to-matlab-interface/' rel='bookmark' title='JMI &#8211; Java-to-Matlab Interface'>JMI &#8211; Java-to-Matlab Interface</a> <small>JMI enables calling Matlab functions from within Java. This article explains JMI's core functionality....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/matlab-java-interface-using-static-control/' rel='bookmark' title='Matlab-Java interface using a static control'>Matlab-Java interface using a static control</a> <small>The switchyard function design pattern can be very useful when setting Matlab callbacks to Java GUI controls. This article explains why and how....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/using-groovy-in-matlab/' rel='bookmark' title='Using Groovy in Matlab'>Using Groovy in Matlab</a> <small>Groovy code can seamlessly be run from within Matlab. ...</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>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=BJ320yMfbnQ:fuQbyzcIlTI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=BJ320yMfbnQ:fuQbyzcIlTI:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=BJ320yMfbnQ:fuQbyzcIlTI:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=BJ320yMfbnQ:fuQbyzcIlTI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=BJ320yMfbnQ:fuQbyzcIlTI:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=BJ320yMfbnQ:fuQbyzcIlTI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=BJ320yMfbnQ:fuQbyzcIlTI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=BJ320yMfbnQ:fuQbyzcIlTI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=BJ320yMfbnQ:fuQbyzcIlTI:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=BJ320yMfbnQ:fuQbyzcIlTI:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/BJ320yMfbnQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/matclipse-eclipse-matlab-interface/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/matclipse-eclipse-matlab-interface/</feedburner:origLink></item>
		<item>
		<title>Customizing figure toolbar background</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/kO8OkJobsdk/</link>
		<comments>http://undocumentedmatlab.com/blog/customizing-figure-toolbar-background/#comments</comments>
		<pubDate>Wed, 20 Feb 2013 18:00:35 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Figure]]></category>
		<category><![CDATA[Toolbar]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3634</guid>
		<description><![CDATA[Setting the figure toolbar's background color can easily be done using just a tiny bit of Java magic powder. This article explains how.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/customizing-standard-figure-toolbar-menubar/' rel='bookmark' title='Customizing the standard figure toolbar, menubar'>Customizing the standard figure toolbar, menubar</a> <small>The standard figure toolbar and menubar can easily be modified to include a list of recently-used files....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/figure-toolbar-components/' rel='bookmark' title='Figure toolbar components'>Figure toolbar components</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/figure-toolbar-customizations/' rel='bookmark' title='Figure toolbar customizations'>Figure toolbar customizations</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to customize the Matlab figure toolbar....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/javacomponent-background-color/' rel='bookmark' title='Javacomponent background color'>Javacomponent background color</a> <small>This article explains how to align Java component background color with a Matlab color....</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>In one of my projects, I needed to present a radar (polar) plot. Such plots are usually drawn on a black background and I wanted all the plot controls to blend into this background.</p>
<div class="wp-caption alignright" style="width: 433px"><img alt="Matlab figure having black toolbar background" src="http://UndocumentedMatlab.com/images/Playback.gif" title="Matlab figure having black toolbar background" width="423" height="479" /><p class="wp-caption-text">Matlab figure having black toolbar background</p></div>
<p>For the plot itself I used a variation of Matlab&#8217;s buggy <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/polar.html">polar</a> function, which I modified to enable proper dynamic resize / zoom / pan, bypass figure-renderer issues with patches and data-cursors, and other similar annoyances. Pretty standard stuff.</p>
<p>For the slider I&#8217;ve used a <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/slider.html"><code>javax.swing.JSlider</code></a> having a <a target="_blank" href="http://undocumentedmatlab.com/blog/continuous-slider-callback/">continuous-movement callback</a>. Again, for readers of this blog this is nothing special:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #080;">&#91;</span>jSlider,hSlider<span style="color: #080;">&#93;</span> = javacomponent<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'javax.swing.JSlider'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">0</span>,<span style="color: #33f;">0</span>,.01,<span style="color: #33f;">0.1</span><span style="color: #080;">&#93;</span>,hFig<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hSlider, <span style="color:#A020F0;">'Units'</span>,<span style="color:#A020F0;">'norm'</span>,<span style="color:#A020F0;">'pos'</span>,<span style="color: #080;">&#91;</span>.15,<span style="color: #33f;">0</span>,.7,.05<span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jSlider, <span style="color:#A020F0;">'Background'</span>,java.<span style="">awt</span>.<span style="">Color</span>.<span style="">black</span>, <span style="color: #F0F;">...</span>
             <span style="color:#A020F0;">'Value'</span>,<span style="color: #33f;">0</span>, <span style="color:#A020F0;">'Maximum'</span>,duration, <span style="color: #F0F;">...</span>
             <span style="color:#A020F0;">'StateChangedCallback'</span>,<span style="color: #080;">&#123;</span><span style="color: #F0F;">@</span>cbSlider,hFig,axPlayback<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Setting the background color for all the GUI components to black was easy. But setting the toolbar&#8217;s background to black turned out to be a bit more interesting, and is the topic of this week&#8217;s article.<br />
<span id="more-3634"></span></p>
<p><center><div class="wp-caption aligncenter" style="width: 433px"><img alt="Standard Matlab figure toolbar - yuck!" src="http://UndocumentedMatlab.com/images/Toolbar1.gif" title="Standard Matlab figure toolbar - yuck!" width="423" height="114" /><p class="wp-caption-text">Standard Matlab figure toolbar - yuck!</p></div></center></p>
<p>The first step, naturally, is to <a target="_blank" href="http://undocumentedmatlab.com/blog/figure-toolbar-components/">get the toolbar&#8217;s handle</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hToolbar = findall<span style="color: #080;">&#40;</span>hFig,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'FigureToolBar'</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>In my case, I programmatically create the figure and use the default figure toolbar, whose tag value is always &#8216;FigureToolBar&#8217;. If I had used a custom toolbar, I would naturally use the corresponding tag (for example, if you create a custom toolbar using GUIDE, then the tag name will probably be &#8216;toolbar1&#8242; or something similar).</p>
<p>Since I&#8217;m setting the figure programmatically, I need to manually remove several unuseful toolbar controls. I do this by <a target="_blank" href="http://undocumentedmatlab.com/blog/modifying-default-toolbar-menubar-actions/">directly accessing the toolbar control handles</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">delete</span><span style="color: #080;">&#40;</span>findall<span style="color: #080;">&#40;</span>hToolbar,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'Plottools.PlottoolsOn'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">delete</span><span style="color: #080;">&#40;</span>findall<span style="color: #080;">&#40;</span>hToolbar,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'Plottools.PlottoolsOff'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">delete</span><span style="color: #080;">&#40;</span>findall<span style="color: #080;">&#40;</span>hToolbar,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'Annotation.InsertColorbar'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">delete</span><span style="color: #080;">&#40;</span>findall<span style="color: #080;">&#40;</span>hToolbar,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'DataManager.Linking'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">delete</span><span style="color: #080;">&#40;</span>findall<span style="color: #080;">&#40;</span>hToolbar,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'Standard.EditPlot'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span></pre></div></div>

<p>For setting the bgcolor, we get the <a target="_blank" href="http://undocumentedmatlab.com/blog/customizing-standard-figure-toolbar-menubar/#Toolbar">toolbar&#8217;s underlying Java component</a>, then sprinkle some Java magic power:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% ensure the toolbar is visible onscreen</span>
<span style="color: #0000FF;">drawnow</span>;
&nbsp;
<span style="color: #228B22;">% Get the underlying JToolBar component</span>
jToolbar = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hToolbar,<span style="color:#A020F0;">'JavaContainer'</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'ComponentPeer'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Set the bgcolor to black</span>
color = java.<span style="">awt</span>.<span style="">Color</span>.<span style="">black</span>;
jToolbar.<span style="">setBackground</span><span style="color: #080;">&#40;</span>color<span style="color: #080;">&#41;</span>;
jToolbar.<span style="">getParent</span>.<span style="">getParent</span>.<span style="">setBackground</span><span style="color: #080;">&#40;</span>color<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Remove the toolbar border, to blend into figure contents</span>
jToolbar.<span style="">setBorderPainted</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Remove the separator line between toolbar and contents</span>
jFrame = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>hFig<span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span>;
jFrame.<span style="">showTopSeparator</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Unfortunately, this is not enough. The reason is that some of Matlab&#8217;s standard toolbar icons use non-opaque Java button controls (thereby showing the new black bgcolor), whereas other icons use opaque buttons, with a hard-coded gray background (I feel like spanking someone&#8230;). I&#8217;ve already <a target="_blank" href="http://undocumentedmatlab.com/blog/figure-toolbar-customizations/">touched upon this issue briefly</a> a few years ago.</p>
<p><center><div class="wp-caption aligncenter" style="width: 433px"><img alt="Matlab figure toolbar with black background, some opaque buttons" src="http://UndocumentedMatlab.com/images/Toolbar2.gif" title="Matlab figure toolbar with black background, some opaque buttons" width="423" height="114" /><p class="wp-caption-text">Matlab figure toolbar with black background, some opaque buttons</p></div></center></p>
<p>Luckily, all is not lost: we simply need to loop over all the JToolBar&#8217;s components and force them to be non-opaque with a black bgcolor. In cases where the component is compound (e.g., the Brush Data <a target="_blank" href="http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool/"><i><b>uisplittool</b></i></a>), we need to set the bgcolor for all the sub-components:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">jtbc = jToolbar.<span style="">getComponents</span>;
<span style="color: #0000FF;">for</span> idx=<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>jtbc<span style="color: #080;">&#41;</span>
    jtbc<span style="color: #080;">&#40;</span>idx<span style="color: #080;">&#41;</span>.<span style="">setOpaque</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
    jtbc<span style="color: #080;">&#40;</span>idx<span style="color: #080;">&#41;</span>.<span style="">setBackground</span><span style="color: #080;">&#40;</span>color<span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">for</span> childIdx = <span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>jtbc<span style="color: #080;">&#40;</span>idx<span style="color: #080;">&#41;</span>.<span style="">getComponents</span><span style="color: #080;">&#41;</span>
        jtbc<span style="color: #080;">&#40;</span>idx<span style="color: #080;">&#41;</span>.<span style="">getComponent</span><span style="color: #080;">&#40;</span>childIdx-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>.<span style="">setBackground</span><span style="color: #080;">&#40;</span>color<span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div>

<p>&#8230;finally ending up with the blended appearance that appears at the top of this article.</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/customizing-standard-figure-toolbar-menubar/' rel='bookmark' title='Customizing the standard figure toolbar, menubar'>Customizing the standard figure toolbar, menubar</a> <small>The standard figure toolbar and menubar can easily be modified to include a list of recently-used files....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/figure-toolbar-components/' rel='bookmark' title='Figure toolbar components'>Figure toolbar components</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/figure-toolbar-customizations/' rel='bookmark' title='Figure toolbar customizations'>Figure toolbar customizations</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to customize the Matlab figure toolbar....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/javacomponent-background-color/' rel='bookmark' title='Javacomponent background color'>Javacomponent background color</a> <small>This article explains how to align Java component background color with a Matlab color....</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=kO8OkJobsdk:F59RP865yHA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=kO8OkJobsdk:F59RP865yHA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=kO8OkJobsdk:F59RP865yHA:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=kO8OkJobsdk:F59RP865yHA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=kO8OkJobsdk:F59RP865yHA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=kO8OkJobsdk:F59RP865yHA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=kO8OkJobsdk:F59RP865yHA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=kO8OkJobsdk:F59RP865yHA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=kO8OkJobsdk:F59RP865yHA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=kO8OkJobsdk:F59RP865yHA:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/kO8OkJobsdk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/customizing-figure-toolbar-background/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/customizing-figure-toolbar-background/</feedburner:origLink></item>
		<item>
		<title>Getting default HG property values</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/rdMWFnM6UDE/</link>
		<comments>http://undocumentedmatlab.com/blog/getting-default-hg-property-values/#comments</comments>
		<pubDate>Wed, 13 Feb 2013 18:00:01 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[GUI]]></category>
		<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>
		<category><![CDATA[UIInspect]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3622</guid>
		<description><![CDATA[Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this.  
<pre> </pre>Related posts:<ol>
<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>
<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/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/setting-class-property-types/' rel='bookmark' title='Setting class property types'>Setting class property types</a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>All Matlab&#8217;s Handle Graphics (HG) property have default values. These values are used unless we specifically override the property value. For example, in R2012a, Matlab <i><b>figure</b></i> handles have 62 documented and 28 <a target="_blank" href="http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/">undocumented</a> properties, all of which have some default value. When we create a new Matlab figure, we typically override only a handful of these properties. </p>
<div class="wp-caption alignright" style="width: 269px"><img alt="How Matlab determines an HG property value" src="http://www.mathworks.com/help/matlab/creating_plots/hg_objects7.gif" title="How Matlab determines an HG property value" width="259" height="543" /><p class="wp-caption-text">How Matlab determines an HG property value</p></div>
<p>For example, we might override the figure&#8217;s <b>Name</b>, <b>NumberTitle</b>, <b>Position</b>, <b>Visible</b>, <b>Colormap</b> and perhaps a few other properties. All the others are either read-only (i.e., un-settable), or left at their default values. This is also true for all HG objects: axes, images, plots, patches, uicontrols, annotations, Java control containers etc.</p>
<p>Matlab makes a distinction between <i>factory</i> and <i>default</i> values. Users can modify the default values, but not the factory values, which makes sense. In essence, user-specified property values override the default values, which in turn override the factory values. I find that this makes the process of using default values quite intuitive. I like this factory/default design.</p>
<p>Matlab has a dedicated <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/creating_plots/setting-default-property-values.html">doc page</a> explaining how we can use, set and reset the default property values.</p>
<p>Unfortunately, MathWorks has not seen fit to explain how to get the full list of current default defaults, nor how to get the factory values. Today&#8217;s article provides the missing manual pages and completes the picture.<br />
<span id="more-3622"></span></p>
<h3 id="accessing">Accessing default and factory property values</h3>
<p>To access any specific property&#8217;s default value, we need to compose a fictitious property name from the string &#8216;Default&#8217; or &#8216;Factory&#8217;, followed by the object&#8217;s type (&#8216;Figure&#8217;, &#8216;Axes&#8217;, &#8216;Line&#8217; etc., as reported by the object&#8217;s <b>Type</b> property), and lastly the property name. For example: <b>DefaultFigureColor</b> or <b>FactoryAxesUnits</b>. As with all HG properties, these names are case insensitive. These fictitious properties all belong to Matlab&#8217;s root (0) handle.</p>
<p>We can now <i><b>get</b></i> and <i><b>set</b></i> the values of any of these fictitious properties (naturally, factory properties cannot be set):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'FactoryFigureUnits'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
pixels
&nbsp;
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'FactoryFigureColor'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
     <span style="color: #33f;">0</span>     <span style="color: #33f;">0</span>     <span style="color: #33f;">0</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'DefaultFigureColor'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
                       <span style="color: #33f;">0.8</span>                       <span style="color: #33f;">0.8</span>                       <span style="color: #33f;">0.8</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'DefaultFigureColor'</span>,<span style="color:#A020F0;">'y'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% new figures will now have a yellow background color...</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'DefaultFigureColor'</span>,<span style="color:#A020F0;">'factory'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% resets the default value to the factory value [0,0,0]=black</span></pre></div></div>

<p>Note that since the default and factory property names are fictitious (i.e., dynamic properties that are parsed on-the-fly), they do not appear when you <i><b>get(0)</b></i>, <i><b>getundoc(0)</b></i> or even <i><b>uiinspect(0)</b></i>.</p>
<p>My <a target="_blank" href="http://undocumentedmatlab.com/blog/uiinspect/"><i><b>uiinspect</b></i> utility</a> reports the factory values in its property-details panel, along with additional meta-data such as whether the properties are settable, readable etc.</p>
<p><center><div class="wp-caption aligncenter" style="width: 505px"><img alt="uiinspect's 'Other properties' meta-data table" src="http://UndocumentedMatlab.com/images/uiinspect_properties2.gif" title="uiinspect's 'Other properties' meta-data table" width="495" height="317" /><p class="wp-caption-text">uiinspect's 'Other properties' meta-data table</p></div></center></p>
<h3 id="list">Getting the full list of factory/default values</h3>
<p>To get the long list of factory values, simply <i><b>get</b></i> a partial fictitious property name:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'factory'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> = 
                         factoryFigureAlphamap<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x64 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
                       factoryFigureBusyAction<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'queue'</span>
                    factoryFigureButtonDownFcn<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
                         factoryFigureClipping<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                  factoryFigureCloseRequestFcn<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'closereq'</span>
                            factoryFigureColor<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>
                        <span style="color: #080;">&#40;</span><span style="color: #F0F;">...</span> <span style="color: #33f;">655</span> additional <span style="color: #0000FF;">properties</span> <span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'default'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> = 
               defaultTextColor<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>
              defaultAxesXColor<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>
              defaultAxesYColor<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>
              defaultAxesZColor<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>
          defaultPatchFaceColor<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>
          defaultPatchEdgeColor<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>
               defaultLineColor<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>
    defaultFigureInvertHardcopy<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
             defaultFigureColor<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>
               defaultAxesColor<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;">1</span><span style="color: #080;">&#93;</span>
          defaultAxesColorOrder<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>7x3 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
          defaultFigureColormap<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>64x3 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
        defaultSurfaceEdgeColor<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>
         defaultFigurePaperType<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'A4'</span>
        defaultFigurePaperUnits<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'centimeters'</span>
         defaultFigurePaperSize<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">20.98404194812</span> <span style="color: #33f;">29.67743169791</span><span style="color: #080;">&#93;</span>
          defaultFigurePosition<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">200</span> <span style="color: #33f;">200</span> <span style="color: #33f;">560</span> <span style="color: #33f;">420</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'DefaultAxes'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> = 
        defaultAxesXColor<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>
        defaultAxesYColor<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>
        defaultAxesZColor<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>
         defaultAxesColor<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;">1</span><span style="color: #080;">&#93;</span>
    defaultAxesColorOrder<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>7x3 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span></pre></div></div>

<p>We can see that the defaults list is much shorter than the factory list. There are very few actual default overrides of the factory values. In fact, if we try to get the default value of a property that was not overridden (e.g., <b>DefaultFigureNumberTitle</b>), Matlab is smart enough to return the factory value (in this case, <b>FactoryFigureNumberTitle</b>=&#8217;on&#8217;).</p>
<h3 id="hidden">Hidden properties</h3>
<p>Hidden (undocumented) properties are not shown by default, but you can always access them <a target="_blank" href="http://undocumentedmatlab.com/blog/plot-linesmoothing-property/#comment-8807">directly</a>, and their list can also be seen if we set the root handle&#8217;s <a target="_blank" href="http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/"><b>HideUndocumented</b> property</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'FactoryAxesLooseInset'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
         <span style="color: #33f;">0.13</span>         <span style="color: #33f;">0.11</span>         <span style="color: #33f;">0.095</span>         <span style="color: #33f;">0.075</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'DefaultPatchLineSmoothing'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
off
&nbsp;
&gt;&gt; <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'DefaultLineLineSmoothing'</span>,<span style="color:#A020F0;">'on'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% default appears to be 'off' for Windows, 'on' for Macs</span>
&nbsp;
&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; allPropDefaults = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'factory'</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">fieldnames</span><span style="color: #080;">&#40;</span>allPropDefaults<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>   <span style="color: #228B22;">% 661 documented + 277 undocumented properties</span>
<span style="color: #0000FF;">ans</span> =
   <span style="color: #33f;">938</span></pre></div></div>

<h3 id="factory">Factory values internals</h3>
<p>For those interested in some internals, the factory values are stored (and can be accessed) via the object&#8217;s UDD reference, or rather the <i><b>schema.prop</b></i> reference of the properties (additional information on UDD properties can be found <a target="_blank" href="http://undocumentedmatlab.com/blog/udd-properties/">here</a>). For example:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0</span>,<span style="color:#A020F0;">'FactoryFigurePosition'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
   <span style="color: #33f;">100</span>   <span style="color: #33f;">100</span>   <span style="color: #33f;">660</span>   <span style="color: #33f;">520</span>
&nbsp;
&gt;&gt; hProp = <span style="color: #0000FF;">findprop</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'pos'</span><span style="color: #080;">&#41;</span>
hProp =
	schema.<span style="">prop</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hProp<span style="color: #080;">&#41;</span>
            Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'Position'</span>
     Description<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
        DataType<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'figurePositionType'</span>
    FactoryValue<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">100</span> <span style="color: #33f;">100</span> <span style="color: #33f;">660</span> <span style="color: #33f;">520</span><span style="color: #080;">&#93;</span>
     AccessFlags<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
         Visible<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
     GetFunction<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
     SetFunction<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; hProp.<span style="">FactoryValue</span>
<span style="color: #0000FF;">ans</span> =
   <span style="color: #33f;">100</span>   <span style="color: #33f;">100</span>   <span style="color: #33f;">660</span>   <span style="color: #33f;">520</span></pre></div></div>

<p>Note that in this example, the <b>FactoryFigurePosition</b> value ([100 100 660 520]) is different than the <b>DefaultFigurePosition</b> value ([200 200 560 420]), which overrides it.</p>
<h3 id="conclusion">Conclusion</h3>
<p>Setting default values enables easy setup of property values for all instances of an HG property in a Matlab session. It could be very tempting to add such setup to the <i>startup.m</i> file, so that such customizations automatically occur for all Matlab sessions. However, I strongly suggest against this: the moment you will try to run your application on any other computer or Matlab installation, you may find that your GUI/graphics look entirely different.</p>
<p>A much safer approach is to understand how these default values affect your application and then specifically set the desired property values in your m-code. This way, whatever the installation&#8217;s default values are, your application will always retain a consistent look-and-feel.</p>
<p>Have you found or ever used any interesting default or factory property value? If so, please share your experience in a <a href="http://UndocumentedMatlab.com/blog/getting-default-hg-property-values/#respond">comment</a>.</p>
 <p><pre> </pre>Related posts:<ol>
<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>
<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/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/setting-class-property-types/' rel='bookmark' title='Setting class property types'>Setting class property types</a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=rdMWFnM6UDE:tAa_7uf7fWQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=rdMWFnM6UDE:tAa_7uf7fWQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=rdMWFnM6UDE:tAa_7uf7fWQ:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=rdMWFnM6UDE:tAa_7uf7fWQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=rdMWFnM6UDE:tAa_7uf7fWQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=rdMWFnM6UDE:tAa_7uf7fWQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=rdMWFnM6UDE:tAa_7uf7fWQ:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=rdMWFnM6UDE:tAa_7uf7fWQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=rdMWFnM6UDE:tAa_7uf7fWQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=rdMWFnM6UDE:tAa_7uf7fWQ:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/rdMWFnM6UDE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/getting-default-hg-property-values/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/getting-default-hg-property-values/</feedburner:origLink></item>
		<item>
		<title>Solving a Matlab hang problem</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/xUbnmF7ITl0/</link>
		<comments>http://undocumentedmatlab.com/blog/solving-a-matlab-hang-problem/#comments</comments>
		<pubDate>Wed, 06 Feb 2013 18:00:25 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pure Matlab]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3617</guid>
		<description><![CDATA[A very common Matlab hang is apparently due to an internal timing problem that can easily be solved.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/solving-a-matlab-bug-by-subclassing/' rel='bookmark' title='Solving a MATLAB bug by subclassing'>Solving a MATLAB bug by subclassing</a> <small>Matlab's Image Processing Toolbox's impoint function contains an annoying bug that can be fixed using some undocumented properties....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/fixing-a-java-focus-problem/' rel='bookmark' title='Fixing a Java focus problem'>Fixing a Java focus problem</a> <small>Java components added to Matlab GUIs do not participate in the standard focus cycle - this article explains how to fix this problem....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/spicing-up-matlab-uicontrol-tooltips/' rel='bookmark' title='Spicing up Matlab uicontrol tooltips'>Spicing up Matlab uicontrol tooltips</a> <small>Matlab uicontrol tooltips can be spiced-up using HTML and CSS, including fonts, colors, tables and images...</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>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p><div class="wp-caption alignright" style="width: 264px"><img alt="Closing a modal dialog may hang Matlab" src="http://UndocumentedMatlab.com/images/questdlg" title="Closing a modal dialog may hang Matlab" width="254" height="143" /><p class="wp-caption-text">Closing a modal dialog may hang Matlab</p></div> Every now and then I stumble on a case where Matlab hangs, becomes totally unresponsive and requires me to kill the Matlab process externally (via the task manager). The undocumented solution is frustratingly simple (see below), and yet I keep forgetting it. </p>
<p>The last time this happened was only two days ago, and by pure coincidence a reader&#8217;s <a target="_blank" href="http://undocumentedmatlab.com/blog/pause-for-the-better/#comment-152329">comment</a> yesterday happened on the same page where I explained the problem and solution. So I am taking this opportunity to explain the problem and the workaround, before my senility takes over and I forget again&#8230; <img src='http://undocumentedmatlab.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
<span id="more-3617"></span></p>
<h3 id="symptom">The symptom &#8211; Matlab hangs</h3>
<p>The symptom is easily detectable: you&#8217;re happily working on your favorite Matlab GUI application, when suddenly some modal dialog window appears &#8211; perhaps a <i><b>msgbox</b></i>, a <i><b>questdlg</b></i> or an <i><b>inputdlg</b></i>. After clicking the &lt;OK&gt; button, Matlab seems to freeze, and any attempt to close the window or to stop the GUI fails. Forget about Ctrl-C &#8211; it simply hangs. </p>
<p>The only workaround is to open the operating system&#8217;s task manager and kill the Matlab process.</p>
<p>There are several odd things here: Firstly, the task manager shows that the Matlab  process is not consuming any CPU. Secondly, the hang does not appear consistently &#8211; sometimes it does, other times not, making debugging extremely difficult. Moreover, when we debug the code, stepping through the source-code lines one at a time, everything seems to behave perfectly normal; it is only when running the program in continuous mode that the hang appears.</p>
<h3 id="solution">The solution &#8211; adding drawnow</h3>
<p>The underlying reason for the hang appears to be that when we close the modal dialog window, it is sometimes not yet fully destroyed when we proceed with our program. It is my belief that this creates race-conditions which in some cases cause a deadlock between Matlab&#8217;s Main Thread and Java&#8217;s <a target="_blank" href="http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/">Event Dispatch Thread (EDT)</a>. Matlab-EDT synchronization problems are often time-dependent, which explains why the hang sometimes occurs and sometimes not.</p>
<p>While debugging EDT synchronization problems is notoriously difficult, the solution is often extremely simple &#8212; Just add a combination of <i><b>drawnow</b></i> and a short <i><b>pause</b></i>:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">uiwait<span style="color: #080;">&#40;</span><span style="color: #0000FF;">msgbox</span><span style="color: #080;">&#40;</span><span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="display:block;background-color: #ffc;"><span style="color: #0000FF;">drawnow</span>; <span style="color: #0000FF;">pause</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0.05</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% this innocent line prevents the Matlab hang</span></span>&nbsp;
answer = <span style="color: #0000FF;">questdlg</span><span style="color: #080;">&#40;</span><span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span>;
<span style="display:block;background-color: #ffc;"><span style="color: #0000FF;">drawnow</span>; <span style="color: #0000FF;">pause</span><span style="color: #080;">&#40;</span><span style="color: #33f;">0.05</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% this innocent line prevents the Matlab hang</span></span><span style="color: #0000FF;">switch</span> answer
   <span style="color: #F0F;">...</span></pre></div></div>

<p>Adding <i><b>drawnow</b></i> and <i><b>pause</b></i> forces Matlab to flush EDT&#8217;s event queue, thereby ensuring synchronization before proceeding with the Matlab code. This is actually <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/160272#407994">quite important</a> when integrating Java GUI components in Matlab figures (especially before R2008b&#8217;s <i><b>javaObjectEDT</b></i> became available).</p>
<p>In the particular case of the Matlab dialog hang, <i><b>drawnow</b></i> is probably sufficient and <i><b>pause</b></i> is unnecessary. As noted by Bill York (MathWorks&#8217; dev team leader who is responsible for such stuff) <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/answers/7309#answer_11189">here</a>, <i><b>drawnow</b></i> is similar but not exactly the same as <i><b>pause</b></i>. I often use both of them, since I discovered via trial-and-error that in the general case of EDT-related timing issues, different situations respond better to either of them, and I never remember which one to use to ensure proper rendering. So the <i><b>drawnow/pause</b></i> line appears very often in my code, quite possibly even in places where they are not strictly needed.</p>
<p>The actual needed value of the pause may vary, depending on GUI complexity and CPU power/load, but 0.05 seems to be large enough for most cases, while being small enough to be virtually unnoticeable by the user. In rare cases I needed to go as high as 0.1, but then again in some cases it is not needed at all.</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/solving-a-matlab-bug-by-subclassing/' rel='bookmark' title='Solving a MATLAB bug by subclassing'>Solving a MATLAB bug by subclassing</a> <small>Matlab's Image Processing Toolbox's impoint function contains an annoying bug that can be fixed using some undocumented properties....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/fixing-a-java-focus-problem/' rel='bookmark' title='Fixing a Java focus problem'>Fixing a Java focus problem</a> <small>Java components added to Matlab GUIs do not participate in the standard focus cycle - this article explains how to fix this problem....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/spicing-up-matlab-uicontrol-tooltips/' rel='bookmark' title='Spicing up Matlab uicontrol tooltips'>Spicing up Matlab uicontrol tooltips</a> <small>Matlab uicontrol tooltips can be spiced-up using HTML and CSS, including fonts, colors, tables and images...</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>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=xUbnmF7ITl0:QY2k2zXdKtA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=xUbnmF7ITl0:QY2k2zXdKtA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=xUbnmF7ITl0:QY2k2zXdKtA:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=xUbnmF7ITl0:QY2k2zXdKtA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=xUbnmF7ITl0:QY2k2zXdKtA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=xUbnmF7ITl0:QY2k2zXdKtA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=xUbnmF7ITl0:QY2k2zXdKtA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=xUbnmF7ITl0:QY2k2zXdKtA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=xUbnmF7ITl0:QY2k2zXdKtA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=xUbnmF7ITl0:QY2k2zXdKtA:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/xUbnmF7ITl0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/solving-a-matlab-hang-problem/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/solving-a-matlab-hang-problem/</feedburner:origLink></item>
		<item>
		<title>propertiesGUI</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/1SRBNmweryg/</link>
		<comments>http://undocumentedmatlab.com/blog/propertiesgui/#comments</comments>
		<pubDate>Wed, 30 Jan 2013 18:00:44 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[Levente Hunyadi]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3511</guid>
		<description><![CDATA[propertiesGUI is a utility that presents property-value structs in a convenient table format, useful in Matlab GUIs.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/advanced-jide-property-grids/' rel='bookmark' title='Advanced JIDE Property Grids'>Advanced JIDE Property Grids</a> <small>JIDE property grids can use complex cell renderer and editor components and can signal property change events asynchronously to Matlab callbacks...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/jide-property-grids/' rel='bookmark' title='JIDE Property Grids'>JIDE Property Grids</a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/uitable-customization-report/' rel='bookmark' title='Uitable customization report'>Uitable customization report</a> <small>In last week&#8217;s report about uitable sorting, I offered a report that I have written which covers uitable customization in detail. Several people have asked for more details about the...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/date-selection-components/' rel='bookmark' title='Date selection components'>Date selection components</a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Last week I presented a detailed explanation of the <a target="_blank" href="http://undocumentedmatlab.com/blog/uiinspect/"><i><b>uiinspect</b></i> utility</a>, which displays a GUI listing all the properties, callbacks and internal methods of an inspected object. Something like Matlab&#8217;s <i><b>inspect</b></i> tool on steroids. I explained that <i><b>uiinspect</b></i> uses <code>com.mathworks.mlwidgets.inspector.PropertyView</code>, which in turn uses JIDE&#8217;s <a target="_blank" href="http://undocumentedmatlab.com/blog/jide-property-grids/">PropertyTable</a>. <code>PropertyView</code> automatically extracts the inspected object&#8217;s properties and displays them using a corresponding renderer in the <code>PropertyTable</code>.</p>
<div class="wp-caption alignright" style="width: 518px"><img alt="propertiesGUI demo" src="http://UndocumentedMatlab.com/images/propertiesGUI.gif" title="propertiesGUI demo" width="508" height="603" /><p class="wp-caption-text">propertiesGUI demo</p></div>
<p>We often need to present a non-object Matlab construct. For example, it is very common to store an application&#8217;s configuration properties in a struct (using Matlab objects is often impractical and unwarranted) &#8212; it would be very useful to present this configuration dynamically, without having to programmatically scan all struct fields and build a dedicated GUI table. Unfortunately, <code>PropertyView</code> cannot automatically retrospect Matlab structs, which is the reason that the built-in <i><b>inspect</b></i> function fails for such objects. In the general case, we may wish to present a <code>PropertyTable</code> using row-specific renderers and editors, when we have such an un-inspectable object (struct, cell array etc.), or even for a dynamically-created table of properties that is not stored in any single object.</p>
<p>Another limitation of <code>PropertyView</code> is that it immediately assigns updated property values to the inspected object, without allowing any sanity checks to be conducted on the new values, and without enabling the user to cancel property changes.</p>
<p>Last but not least, <code>PropertyView</code> does not enable users to easily modify the way that certain properties are presented. Boolean properties (true/false) always use a checkbox cell-renderer/editor, while we may wish to display a string (on/off) or combo-box instead.</p>
<p>In short, <code>PropertyView</code> is great unless you want to customize stuff, or do something slightly out-of-the-ordinary.</p>
<p>Enter <i><b>propertiesGUI</b></i>, the subject of today&#8217;s article.<br />
<span id="more-3511"></span></p>
<h3 id="utility">The propertiesGUI utility</h3>
<p><i><b>propertiesGUI</b></i>, which can be <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/38864-propertiesgui-display-properties-in-an-editable-context-aware-table">downloaded</a> from the Matlab File Exchange, presents a generic solution to this problem. <i><b>propertiesGUI</b></i> is based on Levente Hunyadi&#8217;s articles <a target="_blank" href="http://undocumentedmatlab.com/blog/tag/levente-hunyadi/">here</a> back in 2010, and on his <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28732-property-grid-using-jide-implementation">&#8220;Property grid&#8221; utility</a> on the File Exchange. </p>
<p><i><b>propertiesGUI</b></i> expects the following syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #080;">&#91;</span>hPropsPane, parameters<span style="color: #080;">&#93;</span> = propertiesGUI<span style="color: #080;">&#40;</span>hParent, parameters<span style="color: #080;">&#41;</span></pre></div></div>

<p>where:</p>
<ul>
<li><code>hParent</code> (input) is an optional handle of a parent GUI container (figure/uipanel/uitab) in which the properties table will appear. If missing or empty or 0, the table will be shown in a new modal dialog window; otherwise it will be embedded in the parent container.</li>
<li><code>parameters</code> (input) is an optional struct or object with data fields. The fields are processed separately to determine their corresponding cell renderer and editor. If <code>parameters</code> is not specified, then the global <code>test_data</code> will be used. If <code>test_data</code> is also empty, then a demo of several different data types will be used.</li>
<li><code>hPropsPane</code> (output) is the handle of the generated properties panel widget, which can be customized to display field descriptions, toolbar, etc.</li>
<li><code>parameters</code> (output) is the resulting (possibly-updated) parameters struct. Naturally, this is only relevant in case of a modal dialog.</li>
</ul>
<p>When passing the properties in an input <code>parameters</code> struct, <i><b>propertiesGUI</b></i> automatically inspects each struct field and assigns a corresponding cell-editor with no description and a field label that reflects the field name. The properties are automatically set as modifiable (editable) and assigned a default callback function (<i>propUpdatedCallback</i> sub-function).</p>
<p>The global <code>test_data</code> variable is updated internally when the &lt;OK&gt; button is clicked. It is meant to enable easy data passing between the properties GUI and other application component. Using global vars is generally <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Action_at_a_distance_%28computer_programming%29">discouraged</a> as bad programming, but it simplifies GUI component interaction and has performance advantages. In this specific case I decided that the benefits of simplicity outweigh the pedagogical aspects. After all, <i><b>propertiesGUI</b></i> is meant to illustrate how to customize/use a properties pane, not to teach GUI programming best practices. In your real-world application you should consider using other information-sharing mechanisms (<i><b>getappdata</b></i> or <i><b>guidata</b></i>, for example).</p>
<h3 id="demo">Usage demo</h3>
<p>For an illustration of <i><b>propertiesGUI</b></i>, simply run it without any parameters to display its demo (see screenshot above):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">propertiesGUI;</pre></div></div>

<p>This creates (in the <i>demoParameters</i> sub-function) the following demo <code>parameters</code> struct:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">      floating_point_property<span style="color: #F0F;">:</span> <span style="color: #33f;">3.14159265358979</span>
      signed_integer_property<span style="color: #F0F;">:</span> <span style="color: #33f;">12</span>
    unsigned_integer_property<span style="color: #F0F;">:</span> <span style="color: #33f;">12</span>
                flag_property<span style="color: #F0F;">:</span> <span style="color: #33f;">1</span>
                file_property<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
              folder_property<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'C:\Yair'</span>
                text_property<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'Sample text'</span>
        fixed_choice_property<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'Yes'</span>  <span style="color:#A020F0;">'No'</span>  <span style="color:#A020F0;">'Maybe'</span><span style="color: #080;">&#125;</span>
     editable_choice_property<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'Yes'</span>  <span style="color:#A020F0;">'No'</span>  <span style="color:#A020F0;">'Maybe'</span>  <span style="color:#A020F0;">''</span><span style="color: #080;">&#125;</span>
                date_property<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 java.<span style="">util</span>.<span style="color: #0000FF;">Date</span><span style="color: #080;">&#93;</span>
        another_date_property<span style="color: #F0F;">:</span> <span style="color: #33f;">734895.957829132</span>
                time_property<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'22:59:16'</span>
            password_property<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'*****'</span>
          IP_address_property<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'10.20.30.40'</span>
                  my_category<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">&#93;</span>
               color_property<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">0.4</span> <span style="color: #33f;">0.5</span> <span style="color: #33f;">0.6</span><span style="color: #080;">&#93;</span>
       another_color_property<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 java.<span style="">awt</span>.<span style="">Color</span><span style="color: #080;">&#93;</span></pre></div></div>

<h3 id="template">A template for customization</h3>
<p><i><b>propertiesGUI</b></i> is meant to be used either as stand-alone, or as a template for customization. For example, we can attach a unique description to each property that will be shown in an internal sub-panel: see the <i>customizePropertyPane</i> and <i>preparePropsList</i> sub-functions.</p>
<p>We can have specific control over each property&#8217;s description, label, editability, cell-editor and callback function. See the <i>preparePropsList</i> sub-functions for some examples. Additional cell-editors/renderers can be added in the <i>newProperty</i> sub-function.</p>
<p>Specific control over the acceptable property values can be achieved by entering custom code into the <i>checkProp</i> sub-function. For example, <i>checkProp</i> already contains skeleton code to highlight missing mandatory field values in yellow, and non-editable properties in gray (see highlighted lines; the necessary modifications to make it work should be self-evident):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> isOk = checkProp<span style="color: #080;">&#40;</span>prop<span style="color: #080;">&#41;</span>
  isOk = <span style="color: #0000FF;">true</span>;
  oldWarn = <span style="color: #0000FF;">warning</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'off'</span>,<span style="color:#A020F0;">'MATLAB:hg:JavaSetHGProperty'</span><span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">warning</span> off MATLAB<span style="color: #F0F;">:</span>hg<span style="color: #F0F;">:</span>PossibleDeprecatedJavaSetHGProperty
  propName = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>prop, <span style="color:#A020F0;">'UserData'</span><span style="color: #080;">&#41;</span>;
  renderer = com.<span style="">jidesoft</span>.<span style="color: #0000FF;">grid</span>.<span style="">CellRendererManager</span>.<span style="">getRenderer</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>prop,<span style="color:#A020F0;">'Type'</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>prop,<span style="color:#A020F0;">'EditorContext'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">warning</span><span style="color: #080;">&#40;</span>oldWarn<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="display:block;background-color: #ffc;">  mandatoryFields = <span style="color: #080;">&#123;</span><span style="color: #080;">&#125;</span>;  <span style="color: #228B22;">% TODO - add the mandatory field-names here</span></span><span style="display:block;background-color: #ffc;">  <span style="color: #0000FF;">if</span> <span style="color: #0000FF;">any</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">strcmpi</span><span style="color: #080;">&#40;</span>propName, mandatoryFields<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">&amp;&amp;</span> <span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>prop,<span style="color:#A020F0;">'Value'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span></span><span style="display:block;background-color: #ffc;">      propColor = java.<span style="">awt</span>.<span style="">Color</span>.<span style="">yellow</span>;</span>      isOk = <span style="color: #0000FF;">false</span>;
<span style="display:block;background-color: #ffc;">  <span style="color: #0000FF;">elseif</span> ~prop.<span style="">isEditable</span></span><span style="display:block;background-color: #ffc;">      <span style="color: #228B22;">%propColor = java.awt.Color.gray;</span></span>      propColor = renderer.<span style="">getBackground</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">else</span>
      propColor = java.<span style="">awt</span>.<span style="">Color</span>.<span style="">white</span>;
  <span style="color: #0000FF;">end</span>
  renderer.<span style="">setBackground</span><span style="color: #080;">&#40;</span>propColor<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% checkProp</span></pre></div></div>

<p>So if we wish to check the validity of the input or user updates, we simply need to enter the relevant checks into <i>checkProp</i>.</p>
<p>Additional control over the appearance and functionality can be achieved via the <code>hPropsPane</code> reference that is returned by <i><b>propertiesGUI</b></i>.</p>
<p>As an example for such customizations, here is a variant of the properties pane, embedded within a <a target="_blank" href="http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/"><i><b>uitab</b></i></a> panel. Note the unique description of the properties, and the absence of the OK/Cancel buttons:</p>
<p><center><div class="wp-caption aligncenter" style="width: 510px"><img alt="Properties panel Integrated within a GUI" src="http://UndocumentedMatlab.com/images/Champ_animated.gif" title="Properties panel Integrated within a GUI" width="500" /><p class="wp-caption-text">Properties panel Integrated within a GUI</p></div></center></p>
<h3 id="TODO">TODO</h3>
<p>Even as a template for customization, <i><b>propertiesGUI</b></i> is still far from perfect. Some potential items on my TODO list for this utility include:</p>
<ul>
<li>Fix the renderer/editor for numeric and cell arrays</li>
<li>Enable more control over appearance and functionality via input parameters (for example: display or hide the OK/Cancel buttons)</li>
<li>Add additional built-in cell editors/renderers: time, slider, point, rectangle (=position), font, &#8230;</li>
</ul>
<p>Do you find <i><b>propertiesGUI</b></i> useful in your work? If so then please share your experience in a comment <a href="http://undocumentedmatlab.com/blog/propertiesgui/#respond">below</a>. Suggestions for improvement of the utility will also be gladly accepted.</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/advanced-jide-property-grids/' rel='bookmark' title='Advanced JIDE Property Grids'>Advanced JIDE Property Grids</a> <small>JIDE property grids can use complex cell renderer and editor components and can signal property change events asynchronously to Matlab callbacks...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/jide-property-grids/' rel='bookmark' title='JIDE Property Grids'>JIDE Property Grids</a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/uitable-customization-report/' rel='bookmark' title='Uitable customization report'>Uitable customization report</a> <small>In last week&#8217;s report about uitable sorting, I offered a report that I have written which covers uitable customization in detail. Several people have asked for more details about the...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/date-selection-components/' rel='bookmark' title='Date selection components'>Date selection components</a> <small>The JIDE package, pre-bundled in Matlab, contains several GUI controls for selecting dates - this article explains how they can be used...</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=1SRBNmweryg:ey_g7eKhLHk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=1SRBNmweryg:ey_g7eKhLHk:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=1SRBNmweryg:ey_g7eKhLHk:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=1SRBNmweryg:ey_g7eKhLHk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=1SRBNmweryg:ey_g7eKhLHk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=1SRBNmweryg:ey_g7eKhLHk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=1SRBNmweryg:ey_g7eKhLHk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=1SRBNmweryg:ey_g7eKhLHk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=1SRBNmweryg:ey_g7eKhLHk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=1SRBNmweryg:ey_g7eKhLHk:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/1SRBNmweryg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/propertiesgui/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/propertiesgui/</feedburner:origLink></item>
		<item>
		<title>uiinspect</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/Kdo8ZudL1Uo/</link>
		<comments>http://undocumentedmatlab.com/blog/uiinspect/#comments</comments>
		<pubDate>Wed, 23 Jan 2013 18:00:09 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Dot-Net]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[UIInspect]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3477</guid>
		<description><![CDATA[uiinspect is a Matlab utility that displays detailed information about an object's methods, properties and callbacks in a single GUI window. 
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/uitable-sorting/' rel='bookmark' title='Uitable sorting'>Uitable sorting</a> <small>Matlab's uitables can be sortable using simple undocumented features...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/uitable-customization-report/' rel='bookmark' title='Uitable customization report'>Uitable customization report</a> <small>In last week&#8217;s report about uitable sorting, I offered a report that I have written which covers uitable customization in detail. Several people have asked for more details about the...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/jide-property-grids/' rel='bookmark' title='JIDE Property Grids'>JIDE Property Grids</a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>After several years in which I have mentioned my <i><b>uiinspect</b></i> utility in posts, I figured it is high time to actually describe this utility in detail. </p>
<div class="wp-caption alignright" style="width: 510px"><img alt="uiinspect in action (Java, HG, COM)" src="http://UndocumentedMatlab.com/images/uiinspect.gif" title="uiinspect in action (Java, HG, COM)" width="500" height="387"/><p class="wp-caption-text">uiinspect in action (Java, HG, COM)</p></div>
<p><i><b>uiinspect</b></i>, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect">downloadable</a> from the Matlab file Exchange, is a Matlab GUI utility that inspects the specified object and provides detailed information about its super-classes, methods, properties, static fields and callbacks in a unified Matlab window. <i><b>uiinspect</b></i> works on a very wide variety of inputs: Matlab/Java/Dot-Net class names and class objects; COM/DCOM objects, Handle Graphics handles etc. </p>
<p>In essence, <i><b>uiinspect</b></i> incorporates the information presented by the following built-in Matlab functions: <i><b>inspect</b></i>, <i><b>get</b></i>, and <i><b>methodsview</b></i>. <i><b>uiinspect</b></i> also presents additional aspects that are not available in any built-in Matlab function (for example, inheritance information, undocumented hidden properties, properties meta-data, grouping of callbacks by type). </p>
<p><i><b>uiinspect</b></i> displays hidden properties and fields that are not normally displayed in Matlab (see my related <a target="_blank" href="http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/">getundoc</a> utility). Property meta-data such as type, accessibility, visibility and default value are also displayed. Object properties and callbacks may be modified interactively within the <i><b>uiinspect</b></i> window.</p>
<p>Of over 40 utilities that I have so-far submitted to the File Exchange, <i><b>uiinspect</b></i> is one of my most complex (together with <a target="_blank" href="http://UndocumentedMatlab.com/blog/findjobj"><i><b>findjobj</b></i></a>). It has undergone 24 revisions since its initial release in 2007. The latest revision has nearly 3000 source-code lines, of which 75% are code lines, 20% are comment lines and the rest are empty spacer lines. That&#8217;s a pretty complex utility to describe, and it relies on plenty of undocumented aspects, so today&#8217;s post will only highlight the important aspects. Readers are more than welcome to have a look at the source code for additional details. It is pretty-well documented, if I may say so myself.<br />
<span id="more-3477"></span></p>
<h3 id="syntax">Usage syntax</h3>
<p>The basic syntax is:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hFig = uiinspect<span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#41;</span></pre></div></div>

<p>Examples:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hFig = uiinspect<span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>;                         <span style="color: #228B22;">% the root handle</span>
hFig = uiinspect<span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #33f;">0</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
hFig = uiinspect<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>;                       <span style="color: #228B22;">% current figure</span>
hFig = uiinspect<span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
uiinspect<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'java.lang.String'</span><span style="color: #080;">&#41;</span>;               <span style="color: #228B22;">% Java classname</span>
uiinspect<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'yes'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;          <span style="color: #228B22;">% Java object</span>
uiinspect<span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;             <span style="color: #228B22;">% Java object</span>
uiinspect<span style="color: #080;">&#40;</span>classhandle<span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;         <span style="color: #228B22;">% UDD class object</span>
uiinspect<span style="color: #080;">&#40;</span><span style="color: #0000FF;">findprop</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'MenuBar'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% UDD property</span>
uiinspect<span style="color: #080;">&#40;</span>actxserver<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Excel.Application'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% COM object</span>
uiinspect<span style="color: #080;">&#40;</span>Employee<span style="color: #080;">&#41;</span>                          <span style="color: #228B22;">% Matlab class object</span>
uiinspect<span style="color: #080;">&#40;</span>?handle<span style="color: #080;">&#41;</span>                           <span style="color: #228B22;">% Matlab metaclass object</span>
uiinspect<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'meta.class'</span><span style="color: #080;">&#41;</span>                      <span style="color: #228B22;">% Matlab class name</span>
uiinspect<span style="color: #080;">&#40;</span>System.<span style="">DateTime</span>.<span style="color: #0000FF;">Now</span><span style="color: #080;">&#41;</span>               <span style="color: #228B22;">% Dot-Net object</span></pre></div></div>

<p><i><b>uiinspect</b></i> returns a handle to the created figure window. <i><b>uiinspect</b></i> opens a regular Matlab figure window which may be accessed via hFig (unlike Matlab&#8217;s <i><b>methodsview</b></i> and <i><b>inspect</b></i> functions which open Java frame that is not accessible from Matlab).</p>
<p>Unlike Matlab&#8217;s functions, multiple <i><b>uiinspect</b></i> windows can be opened simultaneously, for different objects. The differentiation is done based on figure title, which contains the inspected object&#8217;s name (if available) and its class &#8211; reinspecting the same object will reuse the existing figure window, but in all other cases a new figure window will be created. </p>
<h3 id="panels">Main panels</h3>
<p><i><b>uiinspect</b></i> includes the following information panels, that shall be described separately below:</p>
<ul>
<li>Class information (including superclasses, if applicable)</li>
<li>Methods (for objects) or graphic handle hierarchy (for Handle Graphics)</li>
<li>Callbacks (where applicable)</li>
<li>Inspectable properties</li>
<li>Other properties plus full meta-data (where applicable)</li>
</ul>
<p>The panels are fully resizable. We can drag the divider lines up/down or left/right and the contents automatically adjust accordingly. Each panel has a minimal viewable width/height, and the dividers cannot be dragged to squeeze the panels below these minimums &#8211; they can only be minimized, which hides the relevant panel entirely. To minimize a panel, simply click the relevant small arrow mark on the divider. The opposite arrow mark next to it maximizes the panel, effectively minimizing the panel on the other side. Once minimized/maximized, the divider can be restored by simply clicking it once, or by dragging it (again, panel minimum sizes apply). </p>
<p><i><b>uiinspect</b></i> only uses Java panels, so implementing the dividers required use of the simple <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/splitpane.html">JSplitPane</a>. In a general case where we might wish to embed Matlab graphs in one of the side panels, we would need to employ a more sophisticated solution (see my <a target="_blank" href="http://undocumentedmatlab.com/blog/uisplitpane/">UISplitPane</a> utility).</p>
<h3 id="class">Class information</h3>
<p>The top-left panel displays a label with information about the object&#8217;s class and super-classes inheritance (where applicable).</p>
<p>The class name itself is hyper-linked to the class&#8217;s documentation: if this is a standard Java class, then to the official online javadoc for this class which opens up in Matlab&#8217;s internal web browser. In fact, since different Matlab releases use different JVM versions (1.3 through 1.6), the link points to the documentation page corresponding to the JVM version actually used.</p>
<p>If the class is non-Java, the hyperlink displays the class&#8217;s help section in Matlab&#8217;s Command Window / console. The panel&#8217;s tooltip displays the same information in a slightly different manner.</p>
<p>The hyperlink in the label is actually an optical illusion. In fact, the entire label is hyper-linked, and clicking any part of it will display the relevant documentation (a similar optical illusion is used to display the hyperlink at the footer of the utility window). The illusion is achieved using <a target="_blank" href="http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/">Matlab&#8217;s HTML formatting</a>, where the part of the label string consisting of the class name is underlined. The cursor was dynamically modified to a pointed hand-finger when the mouse hovers over the label, using the following simple Java-based command:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">methodsLabel.<span style="">setCursor</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Cursor</span><span style="color: #080;">&#40;</span>java.<span style="">awt</span>.<span style="">Cursor</span>.<span style="">HAND_CURSOR</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Special treatment is done to extract the class&#8217;s superclass, the interfaces that it implements and any possible class qualifiers (for example, &#8220;final&#8221;).</p>
<p>For those interested to dig within the code, all this is done in <i><b>uiinspect</b></i>&#8216;s <i>getMethodsPane</i> function.</p>
<p>Next to the class label, a checkbox is presented (&#8220;Extra&#8221;). Clicking this checkbox displays additional meta-data information (qualifiers, interrupts and inheritance) in the methods pane beneath. Not all classes have all these extra meta-data fields &#8211; only the relevant extra meta-information fields are displayed. If there are is extra meta-data, then the checkbox is not displayed. This is done in the <i>getMethodsTable</i> function.</p>
<h3 id="methods">Methods or HG hierarchy panel</h3>
<p>The utility&#8217;s main panel displays either a table of methods (functions) for a class object, or a tree hierarchy for an HG handle.</p>
<h4 id="class-methods">Class object methods</h4>
<p>The methods table takes the information from the <i>getObjMethods</i> function, which is an adaptation of Matlab&#8217;s built-in <i><b>methodsview</b></i> function. Part of the adaptation is to hyperlink all class references (used in the methods&#8217; inputs, outputs and meta-data), such that clicking them will open new corresponding <i><b>uiinspect</b></i> windows.</p>
<div class="wp-caption alignright" style="width: 478px"><img alt="Class object methods panel" src="http://UndocumentedMatlab.com/images/uiinspect_methods.gif" title="Class object methods panel" width="468" height="219" /><p class="wp-caption-text">Class object methods panel</p></div>
<p>The methods data is displayed within a non-editable Java table (in the <i>getMethodsTable</i> function) that auto-resizes the columns. The table columns are sortable, even sortable on multiple columns by CTRL-clicking (<i><b>methodsview</b></i> allows only simple sorting). This is done using JIDE&#8217;s <a target="_blank" rel="nofollow" href="http://www.jidesoft.com/javadoc/com/jidesoft/grid/TreeTable.html">TreeTable</a> component. The table is placed within a scroll-pane having <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html#scrollbars">automatic scrollbars</a> that only appear as needed.</p>
<p>The table&#8217;s <b>MouseMovedCallback</b> property is set to <i>tbMouseMoved</i>, which updates the mouse cursor (either regular or pointed finger) based on the current mouse position in the table (whether over a hyperlinked cell or not).</p>
<p>The table&#8217;s <b>MousePressedCallback</b> property is set to <i>tbMousePressed</i>, which opens new <i><b>uiinspect</b></i> figure windows for the hyperlinked classes (if any) in the clicked cell.</p>
<h4 id="HG-hierarchy">HG hierarchy tree</h4>
<p>For HG handles, <i>getHandleTree</i> creates a Java tree that displays the hierarchy of HG children (as recursively reported by any HG handle&#8217;s <b>Children</b> property). For convenience, I have chosen to use the built-in component <code>com.mathworks.hg.peer.UITreePeer</code> that underlies the built-in <a target="_blank" href="http://undocumentedmatlab.com/blog/uitree/"><i><b>uitree</b></i></a> function. For performance reasons, the tree is not fully evaluated: the inspected handle&#8217;s <b>Parent</b> is set as the tree&#8217;s <b>Root</b>. The root node is expanded to get all the parent&#8217;s <b>Children</b> (i.e., the inspected handle&#8217;s siblings), and then the inspected handle&#8217;s tree node is again expanded to display its direct descendents. </p>
<div class="wp-caption alignright" style="width: 293px"><img alt="Normal dynamic HG handle tooltip" src="http://UndocumentedMatlab.com/images/uiinspect_HG_tooltip1.gif" title="Normal dynamic HG handle tooltip" width="283" height="115" /><p class="wp-caption-text">Normal dynamic HG handle tooltip</p></div>
<p>A <b>MouseMovedCallback</b> is set on the tree to process mouse hover events in the <i>treeMouseMovedCallback</i> function. This function updates the tree tooltip dynamically, in the sense that it presents a different tooltip for different handles (tree nodes). </p>
<p>Invalid HG handles (this can happen if the HG handle was deleted since the time that <i><b>uiinspect</b></i> generated the tree) are displayed with a special warning message.</p>
<div class="wp-caption alignright" style="width: 360px"><img alt="Invalid HG handle tooltip" src="http://UndocumentedMatlab.com/images/uiinspect_HG_tooltip2.gif" title="Invalid HG handle tooltip" width="350" height="44" /><p class="wp-caption-text">Invalid HG handle tooltip</p></div>
<p>This dynamic tree behavior is achieved by storing the relevant handle information in the <b>UserData</b> of the different tree nodes. Unfortunately, starting in R2012a, Matlab has made a change in the internal support of Java objects, and the <b>UserData</b> property is no longer available. Such a case is detected and the data is stored in the tree nodes&#8217; <b>ApplicationData</b> property instead (using <i><b>setappdata</b>(node,&#8217;userdata&#8217;,&#8230;)</i> ).</p>
<div class="wp-caption alignright" style="width: 640px"><img alt="Dynamic context (right-click) menu" src="http://UndocumentedMatlab.com/images/uiinspect3.gif" title="Dynamic context (right-click) menu" width="630" height="488" /><p class="wp-caption-text">Dynamic context (right-click) menu</p></div>
<p>A <b>MousePressedCallback</b> is set on the tree to process context (right-click) events in the <i>treeMousePressedCallback</i> function. The context-menu is also dynamic, in the sense that it presents a different context menu for different handles (tree nodes), again based on their user-data.</p>
<p>Left-clicking a node is not processed by <i>treeMousePressedCallback</i>, but rather by the tree&#8217;s <b>NodeSelectedCallback</b> which is processed in <i>nodeSelected</i>, and by <b>NodeExpandedCallback</b> which is processed by <i>nodeExpanded</i>. <i>nodeSelected</i> reloads <i><b>uiinspect</b></i> for the selected handle; <i>nodeExpanded</i> merely displays the expanded handle&#8217;s children. </p>
<p>Since the &#8216;+&#8217; sign (which triggers <i>nodeExpanded</i>) and the handle icon (which triggers <i>nodeSelected</i>) are so close, we should be careful to click the &#8216;+&#8217;, otherwise the entire <i><b>uiinspect</b></i> window will reload the tree based on the clicked node&#8230; If anyone has a good idea how to solve this dilemma, then I&#8217;m all ears.</p>
<p>Like the methods table, the tree is also placed in a dynamic scroll-pane that displays scrollbars only as needed.</p>
<h3 id="callbacks">Callbacks panel</h3>
<p>The callbacks panel, computed in <i>getCbsData</i> is based on a reflection of the object&#8217;s data as reported by the undocumented built-in <i><b>classhandle</b></i> function. I aggregate all the object&#8217;s events, as well as all the object property names that end with &#8216;Fcn&#8217; or &#8216;Callback&#8217;. This takes care (I hope) of all the different manners by which different kinds of objects raise events that are trappable in Matlab callbacks. Specifically, it takes care of Java/Matlab classes as well as HG handles and COM objects. If anyone thinks that I have forgotten something, please let me know.</p>
<p>The <i>getCbsPane</i> function then displays the callbacks data (callbacks&#8217; property name and value) in a Java table (JIDE <a target="_blank" href="http://undocumentedmatlab.com/blog/jide-property-grids/">PropertyTable</a>, JIDE TreeTable, or failing those a simple JTable). </p>
<div class="wp-caption alignright" style="width: 561px"><img alt="Modifiable object callbacks" src="http://UndocumentedMatlab.com/images/uiinspect_callbacks.gif" title="Modifiable object callbacks" width="551" height="337" /><p class="wp-caption-text">Modifiable object callbacks</p></div>
<p>The callbacks are automatically grouped by name into logical groups (in <i>getTreeData</i>). For example, all callbacks whose names start with &#8220;Mouse*&#8221; are grouped in the &#8220;Mouse callbacks&#8221; group. The last group is always called &#8220;Other callbacks&#8221; and contains all callbacks for which a matching sibling callback has not been found. The groups are automatically collapsed by default; if only a single group is found then this group is automatically opened (for example, in the case of <i><b>uiinspect</b>(0)</i> ).</p>
<p>The callbacks table&#8217;s toolbar enables displaying the callbacks by groups or sorted alphabetically. It also has &#8220;expand&#8221; and &#8220;collapse&#8221; icons that affect all the groups.</p>
<p>A checkbox next to the table&#8217;s toolbar enables hiding <a target="_blank" href="http://undocumentedmatlab.com/blog/uicontrol-callbacks/">standard Java Swing callbacks</a>. This is important when we inspect Java controls and only wish to see its unique callbacks. When using this checkbox, red Java exceptions are sometimes displayed in the Matlab console &#8211; these are harmless and you can safely ignore them (I hope to find a way to prevent them one day).</p>
<p>The table&#8217;s right column displays the callback properties values (if available). This column is editable and we can interactively modify any callback&#8217;s property. As shown, we can enter callback value in either of Matlab&#8217;s supported formats: string, function handle and (for non-COM objects only!) a cell array of function handle and additional data. An error message will be displayed if the callback value is invalid or cannot be set for some reason.</p>
<p>If it is determined that there are no callbacks, then the callbacks panel is automatically minimized, to enable maximum space for the methods panel above it.</p>
<h3 id="inspector">Properties inspector panel</h3>
<p>The properties inspection panel, prepared in <i>getPropsPane</i>, is actually composed of two separate panes: the top pane uses the built-in Matlab component <code>com.mathworks.mlwidgets.inspector.PropertyView</code>, which in turn uses JIDE&#8217;s <a target="_blank" href="http://undocumentedmatlab.com/blog/jide-property-grids/">PropertyTable</a>. <code>PropertyView</code> is the same component used by Matlab&#8217;s standard <i><b>inspect</b></i> function (that&#8217;s how I came to know it, if anyone wonders). </p>
<div class="wp-caption alignright" style="width: 361px"><img alt="uiinspect's property inspector table" src="http://UndocumentedMatlab.com/images/PropertyTable.gif" title="uiinspect's property inspector table" width="351" height="216" /><p class="wp-caption-text">uiinspect's property inspector table</p></div>
<p>The benefit of using Matlab&#8217;s <code>PropertyView</code> component rather than JIDE&#8217;s <code>PropertyTable</code> is that <code>PropertyView</code> has the very useful method <i>setObject</i> which I use to point the component at the inspected object, which automatically infers its non-hidden properties and updates the table, saving me a lot of work. </p>
<p>There are two drawbacks of using Matlab&#8217;s <code>PropertyView</code>:</p>
<ul>
<li><code>PropertyView</code> only displays non-hidden properties. One day when I have time, I intent to add the hidden properties to the resulting JIDE <code>PropertyTable</code>. But for now it only shows non-hidden properties.</li>
<li><code>PropertyView</code> causes a Matlab crash on some Matlab releases, in case <i><b>dbstop if error</b></i> is active (this can be replicated using Matlab&#8217;s standard <i><b>inspect</b></i>). I therefore regrettably need to disable this specific <i><b>dbstop</b></i>.</li>
</ul>
<p>I&#8217;ve been meaning to do these two fixes ever since I released <i><b>uiinspect</b></i> back in 2007, but for now that&#8217;s the way it is&#8230;</p>
<p>The properties data is retrieved via the <i>getPropsData</i> function. This function uses the built-in Matlab functions <i><b>meta.class.fromName</b>(className)</i> and <i><b>metaclass</b>(classObject)</i> to get the class handle of Matlab classes (in <i>getMetaClass</i>); similarly, <i>loadClass</i> loads the class definition for a Java class. I inspect these class handles for their contained properties. I then use the <i><b>fieldnames</b></i> function to add static class fields, which are not standard properties (for example, &#8220;RED&#8221; is a static field of the <code>java.awt.Color</code> class).</p>
<p>From the class handle, I retrieve the full definition of each property. This includes meta-data such as whether the property is regular or hidden (undocumented); settable or not; gettable or not; and any additional qualifiers (e.g., Sealed, Dependent, Constant, Abstract, Transient, Default (factory) value).</p>
<div class="wp-caption alignright" style="width: 460px"><img alt="Object properties tooltip" src="http://UndocumentedMatlab.com/images/uiinspect_properties1.gif" title="Object properties tooltip" width="450" height="297"/><p class="wp-caption-text">Object properties tooltip</p></div>
<p>We now have a list of all properties and static fields, and this is used to display the entire properties data in the properties panel&#8217;s title (&#8220;Inspectable object properties&#8221;) tooltip. This tooltip, created in <i>updateObjTooltip</i> and <i>getPropsHtml</i>, uses some fancy HTML formatting to display all the object&#8217;s properties and values, color- and font-style-coded to show which of the properties is read-only, hidden, undefined etc.</p>
<div class="wp-caption alignright" style="width: 505px"><img alt="The 'Other properties' meta-data table" src="http://UndocumentedMatlab.com/images/uiinspect_properties2.gif" title="The 'Other properties' meta-data table" width="495" height="317" /><p class="wp-caption-text">The 'Other properties' meta-data table</p></div>
<p>The entire information is also displayed in the properties meta-data pane (&#8220;Other properties&#8221;) beneath JIDE&#8217;s inspector pane. Here we use a simple Java table to display the information in color-coding (gray for read-only properties; blue for static fields; red for irretrievable properties).</p>
<p>Separate checkboxes enable displaying all properties (by default only the properties that are NOT displayed in JIDE&#8217;s inspector table are displayed); and whether or not to display the extra meta-data in the properties table (by default only the property name and current value are displayed).</p>
<p>In some cases (e.g., Dot-Net objects), Matlab&#8217;s inspector does not know how to extract the property-bean information and so the <code>PropertyView</code> inspector is not shown, only the &#8220;other properties&#8221; table.</p>
<p>Both JIDE&#8217;s inspector table and the &#8220;other properties&#8221; table enable the user to modify existing values. Note that in some cases Matlab prevents interactive update of some properties, and in some other cases I have seen Matlab hang when trying to update a few specific properties. But in most cases updating the value does work as expected.</p>
<p>The combination of the inspector table, the meta-data table and the tooltip, enable users to fully understand the accessible properties of the inspected object. Of course, it would have been much better to merge the JIDE inspector table with the hidden properties (=additional rows) and meta-data (=additional columns). But let&#8217;s leave something for the future, shall we?</p>
<h3 id="update">Auto-update mechanism</h3>
<div class="wp-caption alignright" style="width: 529px"><img alt="uiinspect auto-update notice" src="http://UndocumentedMatlab.com/images/uiinspect_update.gif" title="uiinspect auto-update notice" width="519" height="190" /><p class="wp-caption-text">uiinspect auto-update notice</p></div>
<p><i><b>uiinspect</b></i> employs the same auto-update background mechanism used by <i><b>findjobj</b></i> &#8211; after presenting the GUI, the utility silently checks the File Exchange webpage to see whether any newer version of this utility has been uploaded. If so, then a popup notice is presented with the date and description of the latest version. The popup enables users to download the newer version into their Matlab path, or skip. There is also an option to skip the update and not to remind ever again.</p>
<p>I find this background auto-update mechanism quite useful and generic. In fact, I uploaded it as a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/39993-checkVersion">separate File Exchange utility</a> today, following <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/pick/2012/12/14/a-conversation-about-managing-file-exchange-downloads/#comment-17358">Brett Shoelson&#8217;s suggestion</a> last month. You can find the underlying code in the <i>checkVersion</i> function.</p>
<h3 id="TODO">TODO</h3>
<ul>
<li>cleanup internal functions, remove duplicates etc.</li>
<li>link property objects to another <i><b>uiinspect</b></i> window for these objects</li>
<li>display object children (&#038; link to them) &#8211; COM/Java</li>
<li>find a way to merge the other-properties table with the inspector table (hidden props + meta-data)</li>
<li>find a way to use the inspector without disabling <i><b>dbstop if error</b></i></li>
<li>Fix: some fields generate a Java Exception from: <code>com.mathworks.mlwidgets.inspector.PropertyRootNode$PropertyListener$1$1.run</code></li>
<li>Fix: using the &#8220;Hide standard callbacks&#8221; checkbox sometimes issues Java Exceptions on the console</li>
<li>Fix: In HG tree view, sometimes the currently-inspected handle is not automatically selected</li>
</ul>
<p>I would be happy if anyone can help with any of these.</p>
<h3 id="conclusion">Conclusion</h3>
<p>I believe that this has been my longest blog post ever; certainly the one that I have labored most over. This correlates well with the <i><b>uiinspect</b></i> utility, which has been one of my most complex tasks. I&#8217;m guessing I must have invested 100-200 man-hours developing and improving it over the years. </p>
<p>I hope you find <i><b>uiinspect</b></i> as useful and as fun as I do. I believe that its source-code is certainly worth reading if you are interested in any advanced Matlab GUI programming, showing how Java GUI components can be combined in Matlab. Go ahead and <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect">download <i><b>uiinspect</b></i></a> from the Matlab file Exchange.</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/uitable-sorting/' rel='bookmark' title='Uitable sorting'>Uitable sorting</a> <small>Matlab's uitables can be sortable using simple undocumented features...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/' rel='bookmark' title='Minimize/maximize figure window'>Minimize/maximize figure window</a> <small>Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/uitable-customization-report/' rel='bookmark' title='Uitable customization report'>Uitable customization report</a> <small>In last week&#8217;s report about uitable sorting, I offered a report that I have written which covers uitable customization in detail. Several people have asked for more details about the...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/jide-property-grids/' rel='bookmark' title='JIDE Property Grids'>JIDE Property Grids</a> <small>The JIDE components pre-bundled in Matlab enable creating user-customized property grid tables...</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=Kdo8ZudL1Uo:AKOz-g6Mli4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=Kdo8ZudL1Uo:AKOz-g6Mli4:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=Kdo8ZudL1Uo:AKOz-g6Mli4:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=Kdo8ZudL1Uo:AKOz-g6Mli4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=Kdo8ZudL1Uo:AKOz-g6Mli4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=Kdo8ZudL1Uo:AKOz-g6Mli4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=Kdo8ZudL1Uo:AKOz-g6Mli4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=Kdo8ZudL1Uo:AKOz-g6Mli4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=Kdo8ZudL1Uo:AKOz-g6Mli4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=Kdo8ZudL1Uo:AKOz-g6Mli4:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/Kdo8ZudL1Uo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/uiinspect/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/uiinspect/</feedburner:origLink></item>
		<item>
		<title>Customizing the standard figure toolbar, menubar</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/Cz9doN0N-FU/</link>
		<comments>http://undocumentedmatlab.com/blog/customizing-standard-figure-toolbar-menubar/#comments</comments>
		<pubDate>Wed, 09 Jan 2013 18:00:12 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[Figure]]></category>
		<category><![CDATA[Menubar]]></category>
		<category><![CDATA[Toolbar]]></category>
		<category><![CDATA[uitools]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3461</guid>
		<description><![CDATA[The standard figure toolbar and menubar can easily be modified to include a list of recently-used files. 
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/customizing-figure-toolbar-background/' rel='bookmark' title='Customizing figure toolbar background'>Customizing figure toolbar background</a> <small>Setting the figure toolbar's background color can easily be done using just a tiny bit of Java magic powder. This article explains how. ...</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>
<li><a href='http://undocumentedmatlab.com/blog/figure-toolbar-components/' rel='bookmark' title='Figure toolbar components'>Figure toolbar components</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/figure-toolbar-customizations/' rel='bookmark' title='Figure toolbar customizations'>Figure toolbar customizations</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to customize the Matlab figure toolbar....</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>A few days ago, a client asked me to integrate an MRU (most-recently-used) file list in a Matlab GUI window. The naive approach was to add a new &#8220;Recent files&#8221; main menu, but this would look bad. Today I explain how to integrate the MRU list into the toolbar&#8217;s standard &#8220;Open File&#8221; button, as well as into the standard &#8220;File&#8221; main menu.</p>
<h3 id="Menubar">Customizing the standard &#8220;File&#8221; main menu</h3>
<p>Note: this relies on earlier articles about <a target="_blank" href="http://undocumentedmatlab.com/blog/tag/menubar/">customizing the figure menubar</a>, so if you are not comfortable with this topic you might benefit from reading these earlier articles.</p>
<p>Customizing the standard &#8220;File&#8221; main menu is easy. First, let&#8217;s find the &#8220;File&#8221; main menu&#8217;s handle, and add an MRU sub-menu directly to it:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hFileMenu = findall<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>, <span style="color:#A020F0;">'tag'</span>, <span style="color:#A020F0;">'figMenuFile'</span><span style="color: #080;">&#41;</span>;
hMruMenu = <span style="color: #0000FF;">uimenu</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Label'</span>,<span style="color:#A020F0;">'Recent files'</span>, <span style="color:#A020F0;">'Parent'</span>,hFileMenu<span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Our new MRU menu item is created at the end (in this case, at the bottom of the &#8220;File&#8221; main menu list). Let&#8217;s move it upward, between &#8220;New&#8221; and &#8220;Open&#8230;&#8221;, by reordering <code>hFileMenu</code>&#8216;s <b>Children</b> menu items:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hAllMenuItems = allchild<span style="color: #080;">&#40;</span>hFileMenu<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hFileMenu, <span style="color:#A020F0;">'Children'</span>,<span style="color: #0000FF;">fliplr</span><span style="color: #080;">&#40;</span>hAllMenuItems<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">2</span><span style="color: #F0F;">:</span>end-<span style="color: #33f;">1</span>,<span style="color: #33f;">1</span>,<span style="color: #0000FF;">end</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% place in 2nd position, just above the &quot;Open&quot; item</span></pre></div></div>

<p>Now let&#8217;s fix the &#8220;Open&#8230;&#8221; menu item&#8217;s callback to point to our custom <i>openFile()</i> function (unfortunately, the &#8220;Open&#8230;&#8221; menu item has no tag, so we must rely on its label to get its handle):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hOpenMenu = findall<span style="color: #080;">&#40;</span>hFileMenu, <span style="color:#A020F0;">'Label'</span>, <span style="color:#A020F0;">'&amp;Open...'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hOpenMenu, <span style="color:#A020F0;">'Callback'</span>,<span style="color: #F0F;">@</span>openFile<span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Finally, let&#8217;s add the MRU list as a sub-menu of the new <code>hMruMenu</code>. I assume that we have a <i>getMRU()</i> function in our code, which returns a cell-array of filenames:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Add the list of recent files, one item at a time</span>
filenames = getMRU<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">for</span> fileIdx = <span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>filenames<span style="color: #080;">&#41;</span>
    <span style="color: #0000FF;">uimenu</span><span style="color: #080;">&#40;</span>hMruMenu, <span style="color:#A020F0;">'Label'</span>,filenames<span style="color: #080;">&#123;</span>fileIdx<span style="color: #080;">&#125;</span>, <span style="color:#A020F0;">'Callback'</span>,<span style="color: #080;">&#123;</span><span style="color: #F0F;">@</span>openFile,filenames<span style="color: #080;">&#123;</span>fileIdx<span style="color: #080;">&#125;</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 455px"><img alt="Modified standard figure menu-bar" src="http://UndocumentedMatlab.com/images/Menubar_File_Open.png" title="Modified standard figure menu-bar" width="445" height="182" /><p class="wp-caption-text">Modified standard figure menu-bar</p></div></center><br />
<span id="more-3461"></span></p>
<p>Clicking the main &#8220;Open&#8230;&#8221; menu item calls our <i>openFile()</i> function without the optional filename input argument, while selecting one of the MRU files will call the <i>openFile()</i> function with that specific filename as input. The <i>openFile()</i> function could be implemented something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Callback for the open-file functionality (toolbar and menubar)</span>
<span style="color: #0000FF;">function</span> openFile<span style="color: #080;">&#40;</span>hObject,eventData,filename<span style="color: #080;">&#41;</span>
    <span style="color: #228B22;">% If no filename specified, ask for it from the user</span>
    <span style="color: #0000FF;">if</span> <span style="color: #0000FF;">nargin</span> &lt; <span style="color: #33f;">3</span>
        filename = <span style="color: #0000FF;">uigetfile</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#123;</span><span style="color:#A020F0;">'*.csv'</span>,<span style="color:#A020F0;">'Data files (*.csv)'</span><span style="color: #080;">&#125;</span>, <span style="color:#A020F0;">'Open data file'</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>filename<span style="color: #080;">&#41;</span> <span style="color: #F0F;">||</span> isequal<span style="color: #080;">&#40;</span>filename,<span style="color: #33f;">0</span><span style="color: #080;">&#41;</span>
            <span style="color: #0000FF;">return</span>;
        <span style="color: #0000FF;">end</span>
    <span style="color: #0000FF;">end</span>
&nbsp;
    <span style="color: #228B22;">% Open the selected file and read the data</span>
    data = readDataFile<span style="color: #080;">&#40;</span>filename<span style="color: #080;">&#41;</span>;
&nbsp;
    <span style="color: #228B22;">% Update the display</span>
    updateGUI<span style="color: #080;">&#40;</span>data<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">end</span></pre></div></div>

<p>We can take this idea even further by employing <a target="_blank" href="http://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/">HTML formatting</a>, as I have shown in my <a target="_blank" href="http://undocumentedmatlab.com/blog/customizing-menu-items-part-1/">first article of the menubar mini-series</a>:</p>
<p><center><div class="wp-caption aligncenter" style="width: 421px"><img alt="HTML-rendered menu items" src="http://UndocumentedMatlab.com/images/uimenu2b.png" title="HTML-rendered menu items" width="411" height="246"/><p class="wp-caption-text">HTML-rendered menu items</p></div></center></p>
<h3 id="Toolbar">Customizing the standard toolbar&#8217;s &#8220;Open File&#8221; button</h3>
<p>Note: this relies on earlier articles about <a target="_blank" href="http://undocumentedmatlab.com/blog/tag/toolbar/">customizing the figure toolbar</a>, so if you are not comfortable with this topic you might benefit from reading these earlier articles.</p>
<p>The basic idea here is to replace the standard toolbar&#8217;s &#8220;Open File&#8221; pushbutton with a new <a target="_blank" href="http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool/">uisplittool</a> button that will contain the MRU list in its picker-menu.</p>
<p>The first step is to get the handle of the toolbar&#8217;s &#8220;Open File&#8221; button:
</pre>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">hOpen = findall<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>, <span style="color:#A020F0;">'tooltipstring'</span>, <span style="color:#A020F0;">'Open File'</span><span style="color: #080;">&#41;</span>;
hOpen = findall<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>, <span style="color:#A020F0;">'tag'</span>, <span style="color:#A020F0;">'Standard.FileOpen'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% Alternative</span></pre></div></div>

<p>The second alternative is better for non-English Matlab installations where the tooltip text may be different, or in cases where we might have another GUI control with this specific tooltip. On the other hand, the <code>'Standard.FileOpen'</code> tag may be different in different Matlab releases. So choose whichever option is best for your specific needs.</p>
<p>Assuming we have a valid (non-empty) <code>hOpen</code> handle, we get its properties data for later use:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">open_data = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hOpen<span style="color: #080;">&#41;</span>;
hToolbar = open_data.<span style="">Parent</span>;</pre></div></div>

<p>We have all the information we need, so we can now simply delete the existing toolbar open button, and create a new split-button with the properties data that we just got:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">delete</span><span style="color: #080;">&#40;</span>hOpen<span style="color: #080;">&#41;</span>;
hNewOpen = uisplittool<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Parent'</span>,hToolbar, <span style="color: #F0F;">...</span>
                       <span style="color:#A020F0;">'CData'</span>,open_data.<span style="">CData</span>, <span style="color: #F0F;">...</span>
                       <span style="color:#A020F0;">'Tooltip'</span>,open_data.<span style="">TooltipString</span>, <span style="color: #F0F;">...</span>
                       <span style="color:#A020F0;">'ClickedCallback'</span>,<span style="color: #F0F;">@</span>openFile<span style="color: #080;">&#41;</span>;</pre></div></div>

<p>As with the menubar, the button is now created, but it appears on the toolbar's right edge. Let's move it to the far left. We could theoretically reorder <code>hToolbar</code>'s <b>Children</b> as for the menubar above, but Matlab has an internal bug that causes some toolbar buttons to misbehave upon rearranging. Using Java solves this:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">drawnow</span>;  <span style="color: #228B22;">% this innocent drawnow is *very* important, otherwise Matlab might crash!</span>
jToolbar = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hToolbar,<span style="color:#A020F0;">'JavaContainer'</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'ComponentPeer'</span><span style="color: #080;">&#41;</span>;
jButtons = jToolbar.<span style="">getComponents</span>;
jToolbar.<span style="">setComponentZOrder</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#41;</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% Move to the position between &quot;New&quot; and &quot;Save&quot;</span>
jToolbar.<span style="">revalidate</span>;  <span style="color: #228B22;">% update the toolbar's appearance (drawnow will not do this)</span></pre></div></div>

<p>Finally, let's add the list of recent files to the new split-button's picker menu:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% (Use the same list of filenames as for the menubar's MRU list)</span>
jNewOpen = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hNewOpen,<span style="color:#A020F0;">'JavaContainer'</span><span style="color: #080;">&#41;</span>;
jNewOpenMenu = jNewOpen.<span style="">getMenuComponent</span>;
<span style="color: #0000FF;">for</span> fileIdx = <span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>filenames<span style="color: #080;">&#41;</span>
    jMenuItem = handle<span style="color: #080;">&#40;</span>jNewOpenMenu.<span style="">add</span><span style="color: #080;">&#40;</span>filenames<span style="color: #080;">&#123;</span>fileIdx<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'CallbackProperties'</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jMenuItem,<span style="color:#A020F0;">'ActionPerformedCallback'</span>,<span style="color: #080;">&#123;</span><span style="color: #F0F;">@</span>openFile,filenames<span style="color: #080;">&#123;</span>fileIdx<span style="color: #080;">&#125;</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 455px"><img alt="Modified standard figure toolbar" src="http://UndocumentedMatlab.com/images/Toolbar_Open_File.png" title="Modified standard figure toolbar" width="447" height="143" /><p class="wp-caption-text">Modified standard figure toolbar</p></div></center></p>
<p>Clicking the main Open button calls our <i>openFile()</i> function without the optional filename input argument, while clicking the picker button (to the right of the main Open button) and selecting one of the files will call the <i>openFile()</i> function with that specific filename as input.</p>
<p>That's it. Quite painless in fact. </p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/customizing-figure-toolbar-background/' rel='bookmark' title='Customizing figure toolbar background'>Customizing figure toolbar background</a> <small>Setting the figure toolbar's background color can easily be done using just a tiny bit of Java magic powder. This article explains how. ...</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>
<li><a href='http://undocumentedmatlab.com/blog/figure-toolbar-components/' rel='bookmark' title='Figure toolbar components'>Figure toolbar components</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to access existing toolbar icons and how to add non-button toolbar components....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/figure-toolbar-customizations/' rel='bookmark' title='Figure toolbar customizations'>Figure toolbar customizations</a> <small>Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to customize the Matlab figure toolbar....</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=Cz9doN0N-FU:bxp-KrvAcMk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=Cz9doN0N-FU:bxp-KrvAcMk:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=Cz9doN0N-FU:bxp-KrvAcMk:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=Cz9doN0N-FU:bxp-KrvAcMk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=Cz9doN0N-FU:bxp-KrvAcMk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=Cz9doN0N-FU:bxp-KrvAcMk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=Cz9doN0N-FU:bxp-KrvAcMk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=Cz9doN0N-FU:bxp-KrvAcMk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=Cz9doN0N-FU:bxp-KrvAcMk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=Cz9doN0N-FU:bxp-KrvAcMk:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/Cz9doN0N-FU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/customizing-standard-figure-toolbar-menubar/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/customizing-standard-figure-toolbar-menubar/</feedburner:origLink></item>
		<item>
		<title>2012 perspective &amp; plans for 2013</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/8oN2SaMQ1bI/</link>
		<comments>http://undocumentedmatlab.com/blog/2012-perspective/#comments</comments>
		<pubDate>Wed, 02 Jan 2013 21:31:21 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3447</guid>
		<description><![CDATA[2012 has seen a continued steady growth in website content and readership. This post takes an overview of past achievements and future plans.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/2011-perspective/' rel='bookmark' title='2011 perspective &amp; plans for 2012'>2011 perspective &#038; plans for 2012</a> <small>2011 has seen a continued steady growth in readership of this website. This post takes an overview of past achievements and future plans. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/2010-perspective/' rel='bookmark' title='2010 perspective &amp; plans for 2011'>2010 perspective &#038; plans for 2011</a> <small>2009 and 2010 have seen steady growth in readership of this website. This post takes an overview of past achievements and future plans....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/nyc-visit-may-2013/' rel='bookmark' title='New York City visit, 21-24 May 2013'>New York City visit, 21-24 May 2013</a> <small>I will be visiting New York 21-24 May 2013 to speak at the Matlab Computational Finance Conference. ...</small></li>
<li><a href='http://undocumentedmatlab.com/todo/' rel='bookmark' title='TODO'>TODO</a> <small>List of future posts: Setting preferences programmatically Setting system-tray icons and messages Setting and customizing the status bar Database connectivity using JDBC Complex data structures: hashtables, queues, stacks, deques etc....</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>With 2012 behind us and a fresh 2013 ahead, it is time again for a short look at this website&#8217;s achievements so far, and plans for the future.</p>
<p>I started this blog nearly four years ago, thinking it would be nice to post about a few dozen undocumented features. I had no idea whether this material would be of any use to Matlab users, and I expected the website to be a niche blog at best. In fact, I was not sure that at a rate of one article per week I would have enough content for more than a year or two.</p>
<p>200 posts, 2000 reader comments, and 300K unique visitors later, an admission should now be made that I hugely underestimated the impact that this blog would make. In fact, my pipeline of future articles is now longer than ever (a full year long), and the readership growth appears to quickly approach the physical limit of total Matlab community size.</p>
<h3 id="review">2012 in review</h3>
<p>In 2012, I published 50 articles, including:</p>
<ul>
<li>a few posts about integrating 3rd-party Java libraries in Matlab (<a target="_blank" href="http://undocumentedmatlab.com/blog/waterloo-graphics/">Waterloo</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/using-groovy-in-matlab/">Groovy</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/specialized-matlab-plots/">JFreeChart</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/using-java-collections-in-matlab/">Java Collections</a>)</li>
<li>a mini-series about customizations to figure window menus (<a target="_blank" href="http://undocumentedmatlab.com/blog/customizing-menu-items-part-1/">part1</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/customizing-menu-items-part-2/">part2</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/customizing-menu-items-part-3/">part3</a>)</li>
<li>a mini-series about <a target="_blank" href="http://undocumentedmatlab.com/blog/tag/profiler/">customizations to the built-in Matlab profiler</a></li>
<li>a few articles about customizing the Matlab desktop (<a target="_blank" href="http://undocumentedmatlab.com/blog/recovering-previous-editor-state/">editor</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/mlintfailurefiles/">mlint failures</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/trapping-warnings-efficiently/">trapping warnings</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/bold-color-text-in-the-command-window/">Command Window bold text</a>)</li>
<li>many articles about <a target="_blank" href="http://undocumentedmatlab.com/blog/category/java/">Matlab&#8217;s built-in Java</a> and its usages</li>
<li>several articles on Matlab&#8217;s internal memory (<a target="_blank" href="http://undocumentedmatlab.com/blog/matlab-java-memory-leaks-performance/">leaks #1</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/file-deletion-memory-leaks-performance/">leaks #2</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/profiling-matlab-memory-usage/">profiling</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/matlab-mex-in-place-editing/">in-place editing</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/matlabs-internal-memory-representation/">internal format</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/preallocation-performance/">preallocation</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/array-resizing-performance/">resizing</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/internal-matlab-memory-optimizations/">optimizations</a>)</li>
<li>a few articles on compiled (deployed Matlab applications (<a target="_blank" href="http://undocumentedmatlab.com/blog/speeding-up-compiled-apps-startup/">speed-up</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/splash-window-for-deployed-applications/">splash window</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/removing-user-preferences-from-deployed-apps/">privacy</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/disabling-menu-entries-in-deployed-docked-figures/">disabling menu-items</a>)</li>
<li>quite a few articles about miscellaneous undocumented Matlab topics:
<ul>
<li>GUI (<a target="_blank" href="http://undocumentedmatlab.com/blog/using-spinners-in-matlab-gui/">using spinners</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/images-in-matlab-uicontrols-and-labels/">uicontrol images</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/multi-line-uitable-column-headers/"><i><b>uitable</b></i> headers</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/screencapture-utility/">ScreenCapture utility</a>)</li>
<li>graphics (<a target="_blank" href="http://undocumentedmatlab.com/blog/waterloo-graphics/">Waterloo</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/specialized-matlab-plots/">JFreeChart</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/setting-axes-tick-labels-format/">axes tick labels</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/undocumented-scatter-plot-jitter/">scatter plot jitter</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/pinning-annotations-to-graphs/">pinning annotations</a>)</li>
<li>I/O (<a target="_blank" href="http://undocumentedmatlab.com/blog/xlsread-functionality-change-in-r2012a/"><i><b>xlsread</b></i></a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/xlswrite-for-mac-linux/"><i><b>xlswrite</b></i></a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/expanding-urlreads-capabilities/"><i><b>urlread</b></i></a>)</li>
<li>external interfaces (<a target="_blank" href="http://undocumentedmatlab.com/blog/fixing-matlabs-actxserver/"><i><b>actxserver</b></i></a>), etc.</li>
</ul>
</li>
<li>last but not least, a few posts dealing with <a target="_blank" href="http://undocumentedmatlab.com/blog/tag/performance/">performance</a>, which is one of my favorite topics. In fact you will be reading quite a bit more on this in 2013. This is perhaps the place to announce that I am currently writing my second book on the subject of Matlab Performance Tuning. I hope and expect it to be published later this year, and I will of course inform when it is finally published.</li>
</ul>
<p>2012 continued the trend in previous years of hosting articles by guest bloggers:</p>
<ul>
<li><a target="_blank" href="http://undocumentedmatlab.com/blog/tag/malcolm-lidierth/">Malcolm Lidierth</a> wrote about integrating <a target="_blank" href="http://undocumentedmatlab.com/blog/waterloo-graphics/">Waterloo</a> and <a target="_blank" href="http://undocumentedmatlab.com/blog/using-groovy-in-matlab/">Groovy</a>. Malcolm&#8217;s Waterloo mini-series quickly became a super-star in terms of readership, facebook likes, and user comments.</li>
<li><a target="_blank" href="http://undocumentedmatlab.com/blog/tag/donn-shull/">Donn Shull</a> wrote about <a target="_blank" href="http://undocumentedmatlab.com/blog/extending-a-java-class-with-udd/">extending Java classes using UDD</a>. Donn&#8217;s series of UDD articles is one of the website&#8217;s most highly searched-for terms.</li>
<li><a target="_blank" href="http://undocumentedmatlab.com/blog/tag/alexander-mering/">Alexander Mering</a> wrote about <a target="_blank" href="http://undocumentedmatlab.com/blog/disabling-menu-entries-in-deployed-docked-figures/">disabling menu items in deployed applications</a>.</li>
<li><a target="_blank" href="http://undocumentedmatlab.com/blog/tag/jim-hokanson/">Jim Hokanson</a> wrote about <a target="_blank" href="http://undocumentedmatlab.com/blog/expanding-urlreads-capabilities/">extending the built-in <i><b>urlread</b></i> function</a>.</li>
<li><a target="_blank" href="http://undocumentedmatlab.com/blog/tag/peter-li/">Peter Li</a> wrote about the <a target="_blank" href="http://undocumentedmatlab.com/blog/matlabs-internal-memory-representation/">internals of Matlab&#8217;s memory</a> and <a target="_blank" href="http://undocumentedmatlab.com/blog/matlab-mex-in-place-editing/">mex in-place editing</a>.</li>
</ul>
<h3 id="stats">Stats for nerds (and potential advertisers&#8230;)</h3>
<p>Hopefully there was enough material and diversity in there to satisfy different audiences. Judging by the traffic on the site, this appears to be the case indeed. Interest in this website still grows steadily, continuing <a target="_blank" href="http://undocumentedmatlab.com/blog/2011-perspective/">the trend from the past years</a>. To date, 305,500 unique readers have read at least one article here (two on average), in over 560,000 different visits, reaching a new peak of over 7000 unique visits (plus over a thousand subscribers) per week just before the December holidays. These figures are nearly double those from last year. RSS and email subscription has also continued their steady growth pace. In the following graph, the traffic dips are due to the annual December holidays and the site-overhaul in 2011. The growth trend is quite evident:</p>
<p><center><div class="wp-caption aligncenter" style="width: 460px"><a target="_blank" href="http://UndocumentedMatlab.com/images/2012_Dashboard.png"><img alt="Steady readership growth (click for details)" src="http://UndocumentedMatlab.com/images/2012_Dashboard.png" title="Steady readership growth (click for details)" width="450" /></a><p class="wp-caption-text">Steady readership growth (click for details)</p></div></center><br />
<span id="more-3447"></span></p>
<p>How significant are the absolute numbers?</p>
<p>Well, Matlab <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/aboutus/">reportedly</a> has &#8220;more than 1 million&#8221; users worldwide. So 305K readers represents about 30% of the total, as an upper bound. Granted, some of those visitors are innocent googlers who happened to stumble across the website and are not Matlab users. But I think we can safely assume that at least half of the visitors, who have visited the website multiple times, are actual Matlab users. Whichever way you look at it, this represents a significant portion of the total Matlab community. Somehow, despite having no investment in marketing, and (naturally) no active support from MathWorks, this website has reached wide-spread community attention. I can&#8217;t fully express how happy I am about this. <img src='http://undocumentedmatlab.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I take it as a resounding community approval, so I intend to continue expanding the site with additional interesting content.</p>
<p>In the past 2 annual perspectives (<a target="_blank" href="http://undocumentedmatlab.com/blog/2011-perspective/">2011</a>, <a target="_blank" href="http://undocumentedmatlab.com/blog/2010-perspective/">2010</a>) I have shown the readership breakup by country and by city. The relative trends that were presented then are still valid. So this time I will display the breakup of the top reader languages, as reported by their browsers. It seems that over two-thirds of you readers speak English (or at least, your browsers do), with German, French and Spanish coming far behind:</p>
<p><center><div class="wp-caption aligncenter" style="width: 460px"><a target="_blank" href="http://UndocumentedMatlab.com/images/2012_Languages.gif"><img alt="Steady readership growth (click for details)" src="http://UndocumentedMatlab.com/images/2012_Languages.gif" title="Steady readership growth (click for details)" width="450" /></a><p class="wp-caption-text">Steady readership growth (click for details)</p></div></center> </p>
<h3 id="plans">Plans for 2013</h3>
<p>In 2013 I plan to continue posting about undocumented aspects of Matlab. Specific plans include the much-overdue articles on <i><b>uiinspect</b></i> and its close relative <i><b>checkClass</b></i> (this is a promise from last year that I failed to deliver, sorry&#8230;). I also hope to cross out additional items in my <a target="_blank" href="http://undocumentedmatlab.com/todo/">TODO list</a>. Two mini-series that I hope to get around to, are about Matlab-database connectivity and Matlab&#8217;s new toolstrip/ribbon.</p>
<p>There will also be more articles by guest bloggers. I am extremely pleased at the growing list of guest bloggers. If you have an idea for an article, please email me (<a href="mailto:%20altmany%20@gmail.com?subject=Matlab%20training&amp;body=Hi%20Yair,%20&amp;cc=;&amp;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=Matlab training&amp;body=Hi Yair, '); return false;">altmany at gmail</a>).</p>
<p>Finally, last year I started presenting <a target="_blank" href="http://undocumentedmatlab.com/training/">Matlab training courses/seminars</a>, a niche that I hope to expand in 2013. I expect that you will hear more about public events, and I will also continue custom training.</p>
<p>Happy 2013 everybody!</p>
<p>- Yair Altman</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/2011-perspective/' rel='bookmark' title='2011 perspective &amp; plans for 2012'>2011 perspective &#038; plans for 2012</a> <small>2011 has seen a continued steady growth in readership of this website. This post takes an overview of past achievements and future plans. ...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/2010-perspective/' rel='bookmark' title='2010 perspective &amp; plans for 2011'>2010 perspective &#038; plans for 2011</a> <small>2009 and 2010 have seen steady growth in readership of this website. This post takes an overview of past achievements and future plans....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/nyc-visit-may-2013/' rel='bookmark' title='New York City visit, 21-24 May 2013'>New York City visit, 21-24 May 2013</a> <small>I will be visiting New York 21-24 May 2013 to speak at the Matlab Computational Finance Conference. ...</small></li>
<li><a href='http://undocumentedmatlab.com/todo/' rel='bookmark' title='TODO'>TODO</a> <small>List of future posts: Setting preferences programmatically Setting system-tray icons and messages Setting and customizing the status bar Database connectivity using JDBC Complex data structures: hashtables, queues, stacks, deques etc....</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=8oN2SaMQ1bI:ihBneTYRQwc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=8oN2SaMQ1bI:ihBneTYRQwc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=8oN2SaMQ1bI:ihBneTYRQwc:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=8oN2SaMQ1bI:ihBneTYRQwc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=8oN2SaMQ1bI:ihBneTYRQwc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=8oN2SaMQ1bI:ihBneTYRQwc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=8oN2SaMQ1bI:ihBneTYRQwc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=8oN2SaMQ1bI:ihBneTYRQwc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=8oN2SaMQ1bI:ihBneTYRQwc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=8oN2SaMQ1bI:ihBneTYRQwc:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/8oN2SaMQ1bI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/2012-perspective/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/2012-perspective/</feedburner:origLink></item>
		<item>
		<title>Fixing Matlab’s actxserver</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/a03LJDqCFzA/</link>
		<comments>http://undocumentedmatlab.com/blog/fixing-matlabs-actxserver/#comments</comments>
		<pubDate>Wed, 19 Dec 2012 18:00:32 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Pure Matlab]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3416</guid>
		<description><![CDATA[Matlab's COM (ActiveX) server behavior can be fixed in a couple of useful manners.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/fixing-a-java-focus-problem/' rel='bookmark' title='Fixing a Java focus problem'>Fixing a Java focus problem</a> <small>Java components added to Matlab GUIs do not participate in the standard focus cycle - this article explains how to fix this problem....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/running-vb-code-in-matlab/' rel='bookmark' title='Running VB code in Matlab'>Running VB code in Matlab</a> <small>Matlab does not natively enable running VB code, but a nice trick enables us to do just that...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/setting-desktop-tab-completions/' rel='bookmark' title='Setting desktop tab completions'>Setting desktop tab completions</a> <small>The Matlab desktop's Command-Window tab-completion can be customized for user-defined functions...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/image-easter-egg/' rel='bookmark' title='Image Easter egg'>Image Easter egg</a> <small>The default image presented by Matlab's image function has a very interesting undocumented story....</small></li>
</ol><pre> </pre>]]></description>
			<content:encoded><![CDATA[<p>Matlab&#8217;s built-in <i><b>actxserver</b></i> function provides access to <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Component_Object_Model">COM</a>/<a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Distributed_Component_Object_Model">DCOM</a> server applications on Microsoft Windows platforms. This enables us, for example, to open a Microsoft Office document programmatically, and modify it from within Matlab. This in turn can be used, for example, to prepare professional PDF reports, relying on Office&#8217;s ability to save documents in PDF format. Alternately, we could programmatically update cell formatting (colors, fonts, borders etc.) and embed images and graphs in an Excel workbook &#8211; something that the standard <i><b>xlswrite</b></i> cannot do (my <i><b><a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/15192-officedoc-read-write-format-ms-office-docs-xls-doc-ppt">officedoc</a></b></i> utility does this, using the same COM interface).</p>
<p>Note: For some reason, COM servers are called an <i>ActiveX server</i> in Matlab, although the term <i>ActiveX</i> is normally used for <i>clients</i> (i.e., controls), for which we have the <i><b>actxcontrol*</b></i> set of built-in functions.</p>
<p>Today I will focus on two changes that I made to Matlab&#8217;s built-in <i><b>actxserver</b></i> function:</p>
<h3 id="reusing">Reusing an active server <i> (no pun intended&#8230;)</i></h3>
<p>By default, <i><b>actxserver</b></i> starts a new instance of the specified COM server whenever it is called. Sometimes this is indeed useful. However, I find that in the vast majority of cases, I actually want to reuse an existing server instance if it is currently running. For example, it is <u>much</u> faster and more memory-efficient to open an Excel workbook file in an existing Excel process, than to open it in a new dedicated process.</p>
<p>In R2007a, Matlab introduced the <i><b>actxGetRunningServer</b></i> function. Unfortunately, it did not see fit to set it as the default behavior for <i><b>actxserver</b></i>, nor even as an optional additional parameter (although MathWorks *did* change the <i><b>actxserver</b></i> function in that very same release, to accept a custom interface parameter). Users need to change their programs to first call <i><b>actxGetRunningServer</b></i>, check whether it works or fails, and then call <i><b>actxserver</b></i> if it fails (meaning that a server process is not currently running and a new one needs to be started):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Try to reuse an existing COM server instance if possible</span>
<span style="color: #0000FF;">try</span>
    hServer = actxGetRunningServer<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'excel.application'</span><span style="color: #080;">&#41;</span>;
    <span style="color: #228B22;">% no crash so probably succeeded to connect to a running server</span>
<span style="color: #0000FF;">catch</span>
    <span style="color: #228B22;">% Never mind - continue normally to start the COM server and connect to it</span>
    hServer = actxserver<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'excel.application'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div>

<p>This is downright silly, I must say.<br />
<span id="more-3416"></span></p>
<p>Moreover, all the existing user and Matlab code that uses <i><b>actxserver</b></i> will continue to start a new server instance rather than reuse existing ones. For example, the widely-used <i><b>xlsread</b></i> and <i><b>xlswrite</b></i> functions.</p>
<p>Instead of fixing Matlab&#8217;s installed <i>actxserver.m</i> file, which could be problematic when deploying applications to end-users, I created a copy of <i>actxserver.m</i> somewhere in my user folders that is high on the Matlab path. This way I can modify the file and bundle it with any application that I send to clients. The change to this file is simply to add a variant of the code above at the very top of the <i>actxserver.m</i> file, as follows (the new lines are highlighted):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> h = actxserver<span style="color: #080;">&#40;</span>progID, <span style="color: #0000FF;">varargin</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%ACTXSERVER Creates a COM Automation server.</span>
<span style="color: #F0F;">...</span>
<span style="color: #228B22;">% Copyright 2006-2007 The MathWorks, Inc.</span>
<span style="color: #228B22;">% $Revision: 1.8.6.12 $ $Date: 2011/08/13 17:30:50 $</span>
&nbsp;
<span style="color: #0000FF;">error</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">nargchk</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>, <span style="color: #33f;">5</span>, <span style="color: #0000FF;">nargin</span>, <span style="color:#A020F0;">'struct'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="display:block;background-color: #ffc;"><span style="color: #228B22;">% Yair 17/5/2009: Try to reuse an existing COM server instance if possible</span></span><span style="display:block;background-color: #ffc;"><span style="color: #0000FF;">try</span></span><span style="display:block;background-color: #ffc;">    h = actxGetRunningServer<span style="color: #080;">&#40;</span>progID<span style="color: #080;">&#41;</span>;</span><span style="display:block;background-color: #ffc;">    <span style="color: #0000FF;">return</span>;  <span style="color: #228B22;">% no crash so probably succeeded - return</span></span><span style="display:block;background-color: #ffc;"><span style="color: #0000FF;">catch</span></span><span style="display:block;background-color: #ffc;">    <span style="color: #228B22;">% Never mind - continue normally to start the COM server and connect to it</span></span><span style="display:block;background-color: #ffc;"><span style="color: #0000FF;">end</span></span>&nbsp;
machinename = <span style="color:#A020F0;">''</span>;
interface = <span style="color:#A020F0;">'IDispatch'</span>;
<span style="color: #F0F;">...</span></pre></div></div>

<p>This simple change means that all exiting code, including Matlab&#8217;s built-in <i><b>xlsread</b></i> and <i><b>xlswrite</b></i> functions, now try to reuse a running COM server process if possible, starting a new one only if this fails. The code is fault-tolerant in that it also works on old Matlab releases where the <i><b>actxGetRunningServer</b></i> is not available.</p>
<h3 id="fix">Fix of the progID</h3>
<p>The <i>%matlabroot%/toolbox/matlab/winfun/private/newprogid.m</i> function, a private function used by <i><b>actxserver</b></i>, normalizes COM program identifiers (progIDs), which is the string used to locate the COM server. Unfortunately, until R2011a (or specifically, when this was fixed by some MathWorker on June 10, 2010), this function had a bug that caused the normalization to fail. In order to correct this, I simply added the fixed function to the bottom of my modified <i>actxserver.m</i> file:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Taken from: [matlabroot '\toolbox\matlab\winfun\private\newprogid.m']</span>
<span style="color: #0000FF;">function</span> convertedProgID = newprogid<span style="color: #080;">&#40;</span>progID<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">% Copyright 1984-2004 The MathWorks, Inc.</span>
<span style="color: #228B22;">% $Revision: 1.1.8.5 $ $Date: 2004/04/15 00:07:00 $</span>
&nbsp;
convertedProgID = <span style="color: #0000FF;">lower</span><span style="color: #080;">&#40;</span>progID<span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% Yair: in the new version (after 2010/06/10) this line is missing i.e. case-sensitive progID</span>
convertedProgID = regexprep<span style="color: #080;">&#40;</span>convertedProgID, <span style="color:#A020F0;">'_'</span>, <span style="color:#A020F0;">'__'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% Yair 17/5/2009: was progId - probably a bug</span>
convertedProgID = regexprep<span style="color: #080;">&#40;</span>convertedProgID, <span style="color:#A020F0;">'-'</span>, <span style="color:#A020F0;">'___'</span><span style="color: #080;">&#41;</span>;
convertedProgID = regexprep<span style="color: #080;">&#40;</span>convertedProgID, <span style="color:#A020F0;">'\.'</span>, <span style="color:#A020F0;">'_'</span><span style="color: #080;">&#41;</span>;
convertedProgID = regexprep<span style="color: #080;">&#40;</span>convertedProgID, <span style="color:#A020F0;">' '</span>, <span style="color:#A020F0;">'____'</span><span style="color: #080;">&#41;</span>;
convertedProgID = regexprep<span style="color: #080;">&#40;</span>convertedProgID, <span style="color:#A020F0;">'&amp;'</span>, <span style="color:#A020F0;">'_____'</span><span style="color: #080;">&#41;</span>;</pre></div></div>

<p>Note that when MathWorks fixed <i>%matlabroot%/toolbox/matlab/winfun/private/newprogid.m</i> in 2010, they removed the conversion of progID to lower-case, making it case-sensitive. In my modified version above, I have kept the older conversion to lowercase for case-insensitivity.</p>
<h3 id="seminar">Public-service announcements</h3>
<p><center><div class="wp-caption alignright" style="width: 360px"><a target="_blank" rel="nofollow" href="http://www.johnbryce.co.il/content/%D7%99%D7%95%D7%9D-%D7%A4%D7%AA%D7%95%D7%97-%D7%90%D7%9C%D7%A7%D7%98%D7%A8%D7%95%D7%A0%D7%99%D7%A7%D7%94/?source=divur_martze"><img alt="Matlab open training day (Israel) - click for details" src="http://undocumentedmatlab.com/courses/Matlab_open_day_350x225a.png" title="Matlab open training day (Israel) - click for details" width="350" height="225"/></a><p class="wp-caption-text">Matlab open training day (Israel) - click for details</p></div></center></p>
<p>Readers in Israel are invited to attend a free training seminar that I will present on advanced Matlab topics in Herzliya, on Tuesday Jan 8, 2013. The seminar is free, but requires registration. <a target="_blank" rel="nofollow" href="http://www.johnbryce.co.il/content/%D7%99%D7%95%D7%9D-%D7%A4%D7%AA%D7%95%D7%97-%D7%90%D7%9C%D7%A7%D7%98%D7%A8%D7%95%D7%A0%D7%99%D7%A7%D7%94/?source=divur_martze">Additional details here</a>. I will speak in Hebrew, but the presentation will be in English and I will be happy to answer questions in English.</p>
<p>I wish to point readers&#8217; attentions to the recent <a target="_blank" rel="nofollow" href="http://blog.accelereyes.com/blog/2012/12/12/exciting-updates-from-accelereyes/">announcement</a> by AccelerEyes and MathWorks, that they will now merge their parallel-processing solutions into Matlab&#8217;s product line. I assume this also means an out-of-court settlement of MathWorks&#8217; <a target="_blank" rel="nofollow" href="http://news.priorsmart.com/mathworks-v-accelereyes-l4cm/">patent-infringement lawsuit</a>. On the one hand, this is bad news for competition, removing Matlab PCT&#8217;s major competitor from the market. On the other hand, it could mean improved PCT/DCS products, merging Jacket&#8217;s superior performance and functionality directly within Matlab. If I may venture a guess, 2013 will herald a better, faster, more integrated parallel computing solution for Matlab, but we should probably (and quite sadly) say goodbye to Jacket&#8217;s price levels. Such collaborations, generally portrayed as exciting for consumers, are typically much more exciting for the respective shareholders&#8230;</p>
<p>This blog will now take a short winter break, and will return following the New-Year. Happy Holidays/New-Year everyone! Let this upcoming year be another year filled with discoveries, innovation and success!</p>
<p>&nbsp;</p>
 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/fixing-a-java-focus-problem/' rel='bookmark' title='Fixing a Java focus problem'>Fixing a Java focus problem</a> <small>Java components added to Matlab GUIs do not participate in the standard focus cycle - this article explains how to fix this problem....</small></li>
<li><a href='http://undocumentedmatlab.com/blog/running-vb-code-in-matlab/' rel='bookmark' title='Running VB code in Matlab'>Running VB code in Matlab</a> <small>Matlab does not natively enable running VB code, but a nice trick enables us to do just that...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/setting-desktop-tab-completions/' rel='bookmark' title='Setting desktop tab completions'>Setting desktop tab completions</a> <small>The Matlab desktop's Command-Window tab-completion can be customized for user-defined functions...</small></li>
<li><a href='http://undocumentedmatlab.com/blog/image-easter-egg/' rel='bookmark' title='Image Easter egg'>Image Easter egg</a> <small>The default image presented by Matlab's image function has a very interesting undocumented story....</small></li>
</ol></p><pre> </pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=a03LJDqCFzA:Nsf_oO6IjEU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=a03LJDqCFzA:Nsf_oO6IjEU:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=a03LJDqCFzA:Nsf_oO6IjEU:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=a03LJDqCFzA:Nsf_oO6IjEU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=a03LJDqCFzA:Nsf_oO6IjEU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=a03LJDqCFzA:Nsf_oO6IjEU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=a03LJDqCFzA:Nsf_oO6IjEU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=a03LJDqCFzA:Nsf_oO6IjEU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=a03LJDqCFzA:Nsf_oO6IjEU:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=a03LJDqCFzA:Nsf_oO6IjEU:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/a03LJDqCFzA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/fixing-matlabs-actxserver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/fixing-matlabs-actxserver/</feedburner:origLink></item>
		<item>
		<title>Pinning annotations to graphs</title>
		<link>http://feedproxy.google.com/~r/UndocumentedMatlab/~3/aNo0urN_ZeI/</link>
		<comments>http://undocumentedmatlab.com/blog/pinning-annotations-to-graphs/#comments</comments>
		<pubDate>Wed, 12 Dec 2012 18:00:51 +0000</pubDate>
		<dc:creator>Yair Altman</dc:creator>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[getundoc]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[scribe]]></category>
		<category><![CDATA[UDD]]></category>
		<category><![CDATA[UIInspect]]></category>
		<category><![CDATA[Undocumented property]]></category>

		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3398</guid>
		<description><![CDATA[Annotation object can be programmatically set at, and pinned-to, plot axes data points.  
<pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/jfreechart-graphs-and-gauges/' rel='bookmark' title='JFreeChart graphs and gauges'>JFreeChart graphs and gauges</a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<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/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>
<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>Many Matlab users are aware of Matlab&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/creating_plots/how-to-annotate-graphs.html">annotation functionality</a>, which enables us to assign graphic elements such as arrows, lines, ellipses and text labels to Matlab figures. Matlab has a corresponding built-in function, <i><b>annotation</b></i>, that enables creation of annotation objects. Through the handle returned by <i><b>annotation</b></i> we can customize the annotation&#8217;s appearance (for example, line width/style or text font properties).</p>
<h3 id="limitations">Limitations of Matlab annotations</h3>
<p>Unfortunately, <i><b>annotation</b></i> has several major deficiencies, that are in fact related:<br />
<div class="wp-caption alignright" style="width: 416px"><img alt="A Matlab text-arrow annotation (unpinned)" src="http://UndocumentedMatlab.com/images/Annotation_unpinned_animated.gif" title="A Matlab text-arrow annotation (unpinned)" width="406" height="298" /><p class="wp-caption-text">A Matlab text-arrow annotation (unpinned)</p></div></p>
<ol>
<li><i><b>annotation</b></i> requires us to specify the annotation&#8217;s position in normalized <u>figure</u> units. Often, we are interested in an annotation on a plot axes that does NOT span the entire figure&#8217;s content area. To correctly convert the position from plot axes data coordinates to figure coordinates requires non-trivial calculations.</li>
<li>The created annotation is NOT pinned to the plot axes by default. This means that the annotation retains its relative position in the figure when the plot is zoomed, panned or rotated. This results in unintelligible and misleading annotations. We can indeed pin the annotation to the graph, but this requires delicate manual interaction (click the Edit Plot toolbar icon, then right-click the relevant annotation end-point, then select &#8220;Pin to Axes&#8221; from context menu). Unfortunately, the annotation handle does not provide a documented way to do this programmatically.</li>
<li>Finally, the annotation objects are only displayed on top of plot axes &#8211; they are obscured by any GUI uicontrols that may happen to be present in the figure.</li>
</ol>
<p>All of these limitations originate from the underlying implementation of annotation objects in Matlab. This is based on a transparent hidden axes that spans the entire figure&#8217;s content area, on which the annotations are being drawn (also called the <i>scribe layer</i>). The annotations may appear to be connected to the plot axes, but this is merely a visual illusion. In fact, they are located in a separate axes layer. For this reason, <i><b>annotation</b></i> requires figure position &#8211; in fact, the annotation has no information about the axes beneath it. Since plot axes are always obscured by uicontrols, so too is the annotation layer.</p>
<p>Matlab&#8217;s implementation of annotation is an attempt to replicate Java&#8217;s standard <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html">glass-pane mechanism</a>. But whereas the Java glass-pane is a true transparent layer, on top of all other window components (<a target="_blank" rel="nofollow" href="http://www.codebeach.com/2008/03/introduction-to-glass-panes-in-swing.html">examples</a>), Matlab&#8217;s implementation only works for axes. </p>
<p>Oh well, it&#8217;s better than nothing, I guess. But still, it would be nice if we could specify the annotation in graph (plot axes) data units, and have it pinned automatically without requiring manual user interaction.<br />
<span id="more-3398"></span></p>
<h3 id="Debugging">Debugging the problem</h3>
<p>The obvious first place to start debugging this issue is to go to the annotation handle&#8217;s context-menu (accessible via the <b>UIContextMenu</b> property), drill down to the &#8220;Pin&#8221; menu item and take a look at its callback. We could then use the <i><b><a target="_blank" href="http://undocumentedmatlab.com/blog/hgfeval/">hgfeval</a></b></i> function to execute this callback programmatically. Unfortunately, this does not work well, because the context-menu is empty when the annotation is first created. A context-menu is only assigned to the annotation after the Edit Plot toolbar button and then the annotation object are clicked.</p>
<p>Being too lazy in nature to debug this all the way through, I opted for an easier route: I started the Profiler just prior to clicking the context-menu&#8217;s &#8220;Pin to Axes&#8221;, and stopped it immediately afterwards. This showed me the code path (beneath <i>%matlabroot%/toolbox/matlab/scribe/</i>), and placing breakpoints in key code lines enabled me to debug the process step-by-step. This enabled me to take the essence of the pinning code and implement it in my stand-alone application code. </p>
<p>Believe me when I say that the scribe code is complex (anyone say convoluted?). So I&#8217;ll spare you the gruesome details and skip right to the chase.</p>
<h3 id="solution">The solution</h3>
<h5 id="positioning">Positioning the annotation in axes data units</h5>
<p>The first step is to ensure that the initial annotation position is within the figure bounds. Otherwise, the <i><b>annotation</b></i> function will shout. Note that it is ok to move the annotation outside the figure bounds later on (via panning/zooming) &#8211; it is only the initial annotation creation that must be within the figure bounds (i.e., between 0.0-1.0 in normalized X and Y units):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Prepare the annotation's X position</span>
<span style="color: #228B22;">% Note: we need 2 X values: one for the annotation's head, another for the tail</span>
x = <span style="color: #080;">&#91;</span>xValue, xValue<span style="color: #080;">&#93;</span>;
<span style="color: #0000FF;">xlim</span> = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAxes,<span style="color:#A020F0;">'XLim'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Prepare the annotation's Y position</span>
<span style="color: #228B22;">% Note: we need 2 Y values: one for the annotation's head, another for the tail</span>
<span style="color: #228B22;">% Note: we use a static Y position here, spanning the center of the axes.</span>
<span style="color: #228B22;">% ^^^^  We could have used some other Y data value for this</span>
<span style="color: #0000FF;">yLim</span> = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAxes,<span style="color:#A020F0;">'YLim'</span><span style="color: #080;">&#41;</span>;
y = <span style="color: #0000FF;">yLim</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span> + <span style="color: #33f;">0</span>*<span style="color: #0000FF;">sum</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">yLim</span><span style="color: #080;">&#41;</span> + <span style="color: #080;">&#91;</span><span style="color: #33f;">0.1</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>*<span style="color: #0000FF;">diff</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">ylim</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% TODO: handle reverse, log Y axes</span>
&nbsp;
<span style="color: #228B22;">% Ensure that the annotation fits in the window by enlarging</span>
<span style="color: #228B22;">% the axes limits as required</span>
<span style="color: #0000FF;">if</span> xValue &lt; <span style="color: #0000FF;">xlim</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">||</span> xValue &gt; <span style="color: #0000FF;">xlim</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>
    <span style="color: #0000FF;">hold</span><span style="color: #080;">&#40;</span>hAxes,<span style="color:#A020F0;">'on'</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>hAxes,xValue,y<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'-w'</span><span style="color: #080;">&#41;</span>;
    <span style="color: #0000FF;">drawnow</span>;
&nbsp;
    <span style="color: #228B22;">% YLim may have changed, so recalculate y</span>
    <span style="color: #0000FF;">yLim</span> = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAxes,<span style="color:#A020F0;">'YLim'</span><span style="color: #080;">&#41;</span>;
    y = <span style="color: #0000FF;">yLim</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span> + <span style="color: #33f;">0</span>*<span style="color: #0000FF;">sum</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">yLim</span><span style="color: #080;">&#41;</span> + <span style="color: #080;">&#91;</span><span style="color: #33f;">0.1</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>*<span style="color: #0000FF;">diff</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">ylim</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% TODO: handle reverse, log Y-axes</span>
<span style="color: #0000FF;">end</span></pre></div></div>

<p>Next, we convert our plot data units, in order to get the annotation&#8217;s requested position in the expected figure units. For this we use <i>%matlabroot%/toolbox/matlab/scribe/@scribe/@scribepin/topixels.m</i>. This is an internal method of the scribepin UDD class, so in order to use it we need to create a dummy <code>scribepin</code> object. <i>topixels</i> then converts the dummy object&#8217;s position from axes data units to pixel units. We then use the undocumented <i><b><a target="_blank" href="http://undocumentedmatlab.com/blog/bug-and-workaround-in-timeseries-plot/">hgconvertunits</a></b></i> function to convert from pixel units into normalized figure units:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Convert axes data position to figure normalized position</span>
<span style="color: #228B22;">% uses %matlabroot%/toolbox/matlab/scribe/@scribe/@scribepin/topixels.m</span>
scribepin = scribe.<span style="">scribepin</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hAxes,<span style="color:#A020F0;">'DataAxes'</span>,hAxes,<span style="color:#A020F0;">'DataPosition'</span>,<span style="color: #080;">&#91;</span>x;y;<span style="color: #080;">&#91;</span><span style="color: #33f;">0</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#93;</span>'<span style="color: #080;">&#41;</span>;
figPixelPos = scribepin.<span style="">topixels</span>;
hFig = ancestor<span style="color: #080;">&#40;</span>hAxes,<span style="color:#A020F0;">'figure'</span><span style="color: #080;">&#41;</span>;
figPos = getpixelposition<span style="color: #080;">&#40;</span>hFig<span style="color: #080;">&#41;</span>;
figPixelPos<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span> = figPos<span style="color: #080;">&#40;</span><span style="color: #33f;">4</span><span style="color: #080;">&#41;</span> - figPixelPos<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">2</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#93;</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>;
figNormPos = hgconvertunits<span style="color: #080;">&#40;</span>hFig,<span style="color: #080;">&#91;</span>figPixelPos<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>,<span style="color: #0000FF;">diff</span><span style="color: #080;">&#40;</span>figPixelPos<span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span>,<span style="color:#A020F0;">'pixels'</span>,<span style="color:#A020F0;">'norm'</span>,hFig<span style="color: #080;">&#41;</span>;
annotationX = figNormPos<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
annotationY = figNormPos<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #33f;">2</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span> + figNormPos<span style="color: #080;">&#40;</span><span style="color: #33f;">4</span><span style="color: #080;">&#41;</span>*<span style="color: #080;">&#91;</span><span style="color: #33f;">1</span>,<span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>;</pre></div></div>

<h5 id="pinning">Pinning the annotation to the axes data</h5>
<p>Finally, we use the annotation handle&#8217;s <i>pinAtAffordance()</i> method and set the <b>Pin.DataPosition</b> property to the requested X,Y values (we need to do both of these, otherwise the annotation will jump around when we zoom/pan):</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Ensure that the annotation is within the axes bounds, then display it</span>
<span style="color: #0000FF;">if</span> <span style="color: #0000FF;">any</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span>annotationX,annotationY<span style="color: #080;">&#93;</span> &lt; <span style="color: #33f;">0</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">||</span> <span style="color: #0000FF;">any</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span>annotationX,annotationY<span style="color: #080;">&#93;</span> &gt; <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>
    <span style="color: #228B22;">% Annotation position is outside axes boundaries, so bail out without drawing</span>
    hAnnotation = handle<span style="color: #080;">&#40;</span><span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">elseif</span> ~<span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>annotationObj<span style="color: #080;">&#41;</span>
    <span style="color: #228B22;">% Create a text-arrow annotation with the requested string at the requested position</span>
    hAnnotation = handle<span style="color: #080;">&#40;</span>annotation<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'textarrow'</span>, annotationX, annotationY, <span style="color: #F0F;">...</span>
                                    <span style="color:#A020F0;">'String'</span>,annotationStr, <span style="color:#A020F0;">'TextColor'</span>,<span style="color:#A020F0;">'b'</span>, <span style="color:#A020F0;">'Tag'</span>,<span style="color:#A020F0;">'annotation'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
    <span style="color: #228B22;">% Example for setting annotation properties</span>
    hAnnotation.<span style="">TextEdgeColor</span> = <span style="color: #080;">&#91;</span>.8,.8,.8<span style="color: #080;">&#93;</span>;
&nbsp;
    <span style="color: #228B22;">% Pin the annotation object to the required axes position</span>
    <span style="color: #228B22;">% Note: some of the following could fail in certain cases - never mind</span>
    <span style="color: #0000FF;">try</span>
        hAnnotation.<span style="">pinAtAffordance</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
        hAnnotation.<span style="">pinAtAffordance</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>;
        hAnnotation.<span style="">Pin</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>.<span style="">DataPosition</span> = <span style="color: #080;">&#91;</span>xValue, y<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>;
        hAnnotation.<span style="">Pin</span><span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>.<span style="">DataPosition</span> = <span style="color: #080;">&#91;</span>xValue, y<span style="color: #080;">&#40;</span><span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>;
    <span style="color: #0000FF;">catch</span>
        <span style="color: #228B22;">% never mind - ignore (no error)</span>
    <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div>

<p><center><div class="wp-caption aligncenter" style="width: 416px"><img alt="A Matlab text-arrow annotation (pinned)" src="http://UndocumentedMatlab.com/images/Annotation_pinned_animated.gif" title="A Matlab text-arrow annotation (pinned)" width="406" height="298" /><p class="wp-caption-text">A Matlab text-arrow annotation (pinned)</p></div></center></p>
<p>p.s. Notice that all this relies on pure Matlab code (i.e., no mention of the dreaded J-word&#8230;). In fact, practically the entire scribe code is available in m-file format in the base Matlab installation. Masochistic readers may find many hours of pleasure sifting through the scribe code functionality for interesting nuggets such as the one above. If you ever find any interesting items, please drop me an email, or post a comment below.</p>
<h3 id="undocumented">Undocumented annotation properties</h3>
<p>Annotation objects have a <u>huge</u> number of undocumented properties. In fact, they have more undocumented properties than documented ones. You can see this using my <i><b><a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object">uiinspect</a></b></i> or <i><b><a target="_blank" href="http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/">getundoc</a></b></i> utilities. Here is the list for a simple text-arrow annotation, such as the one that we used above:</p>

<div class="wp_syntax"><div class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; getundoc<span style="color: #080;">&#40;</span>hAnnotation<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> = 
              ALimInclude<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                   Afsize<span style="color: #F0F;">:</span> <span style="color: #33f;">6</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>
                 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>
               ColorProps<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>5x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
     EdgeColorDescription<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'Color'</span>
        EdgeColorProperty<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'Color'</span>
                  Editing<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
                EraseMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'normal'</span>
     FaceColorDescription<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'Head Color'</span>
        FaceColorProperty<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'HeadColor'</span>
             FigureResize<span style="color: #F0F;">:</span> <span style="color: #33f;">0</span>
            HeadBackDepth<span style="color: #F0F;">:</span> <span style="color: #33f;">0.35</span>
                HeadColor<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>
            HeadColorMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'auto'</span>
            HeadEdgeColor<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>
            HeadFaceAlpha<span style="color: #F0F;">:</span> <span style="color: #33f;">1</span>
            HeadFaceColor<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>
               HeadHandle<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">patch</span><span style="color: #080;">&#93;</span>
         HeadHypocycloidN<span style="color: #F0F;">:</span> <span style="color: #33f;">3</span>
            HeadLineStyle<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'-'</span>
            HeadLineWidth<span style="color: #F0F;">:</span> <span style="color: #33f;">0.5</span>
               HeadRosePQ<span style="color: #F0F;">:</span> <span style="color: #33f;">2</span>
                 HeadSize<span style="color: #F0F;">:</span> <span style="color: #33f;">10</span>
             HelpTopicKey<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
          IncludeRenderer<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                 MoveMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'mouseover'</span>
                    NormX<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">0.2</span> <span style="color: #33f;">0.4</span><span style="color: #080;">&#93;</span>
                    NormY<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">0.5</span> <span style="color: #33f;">0.7</span><span style="color: #080;">&#93;</span>
                      Pin<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>0x1 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
                   PinAff<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: #080;">&#93;</span>
           PinContextMenu<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>2x1 <span style="color: #0000FF;">uimenu</span><span style="color: #080;">&#93;</span>
                PinExists<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: #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;">0</span> <span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>
        PropertyListeners<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>8x1 <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#93;</span>
        ScribeContextMenu<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>9x1 <span style="color: #0000FF;">uimenu</span><span style="color: #080;">&#93;</span>
                 Selected<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
             Serializable<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                ShapeType<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'textarrow'</span>
                    Srect<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>2x1 <span style="color: #0000FF;">line</span><span style="color: #080;">&#93;</span>
           StoredPosition<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
                TailColor<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>
               TailHandle<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">line</span><span style="color: #080;">&#93;</span>
            TailLineStyle<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'-'</span>
            TailLineWidth<span style="color: #F0F;">:</span> <span style="color: #33f;">0.5</span>
     TextColorDescription<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'Text Color'</span>
            TextColorMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'auto'</span>
        TextColorProperty<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'TextColor'</span>
        TextEdgeColorMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'manual'</span>
            TextEraseMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'normal'</span>
               TextHandle<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 text<span style="color: #080;">&#93;</span>
         UpdateInProgress<span style="color: #F0F;">:</span> <span style="color: #33f;">0</span>
    VerticalAlignmentMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'auto'</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>

 <p><pre> </pre>Related posts:<ol>
<li><a href='http://undocumentedmatlab.com/blog/jfreechart-graphs-and-gauges/' rel='bookmark' title='JFreeChart graphs and gauges'>JFreeChart graphs and gauges</a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<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/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>
<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><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=aNo0urN_ZeI:qGGzWfFkL7Y:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=aNo0urN_ZeI:qGGzWfFkL7Y:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=aNo0urN_ZeI:qGGzWfFkL7Y:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=aNo0urN_ZeI:qGGzWfFkL7Y:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=aNo0urN_ZeI:qGGzWfFkL7Y:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=aNo0urN_ZeI:qGGzWfFkL7Y:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=aNo0urN_ZeI:qGGzWfFkL7Y:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=aNo0urN_ZeI:qGGzWfFkL7Y:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/UndocumentedMatlab?a=aNo0urN_ZeI:qGGzWfFkL7Y:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/UndocumentedMatlab?i=aNo0urN_ZeI:qGGzWfFkL7Y:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/UndocumentedMatlab/~4/aNo0urN_ZeI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://undocumentedmatlab.com/blog/pinning-annotations-to-graphs/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://undocumentedmatlab.com/blog/pinning-annotations-to-graphs/</feedburner:origLink></item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

 Served from: undocumentedmatlab.com @ 2013-05-21 23:07:15 by W3 Total Cache -->
