<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Undocumented Matlab &#187; Undocumented function</title> <atom:link href="http://undocumentedmatlab.com/blog/category/undocumented-function/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Thu, 17 May 2012 12:01:26 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.1</generator> <item><title>Setting axes tick labels format</title><link>http://undocumentedmatlab.com/blog/setting-axes-tick-labels-format/</link> <comments>http://undocumentedmatlab.com/blog/setting-axes-tick-labels-format/#comments</comments> <pubDate>Wed, 18 Apr 2012 18:00:17 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Listeners]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Listener]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema.prop]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2856</guid> <description><![CDATA[Matlab plot axes ticks can be customized in a way that will automatically update whenever the tick values change.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/axes-looseinset-property/' rel='bookmark' title='Axes LooseInset property'>Axes LooseInset property</a> <small>Matlab plot axes have an undocumented LooseInset property that sets empty margins around the axes, and can be set to provide a tighter fit of the axes to their surroundings....</small></li><li><a
href='http://undocumentedmatlab.com/blog/determining-axes-zoom-state/' rel='bookmark' title='Determining axes zoom state'>Determining axes zoom state</a> <small>The information of whether or not an axes is zoomed or panned can easily be inferred from an internal undocumented object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/fig-files-format/' rel='bookmark' title='FIG files format'>FIG files format</a> <small>FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/customizing-matlab-labels/' rel='bookmark' title='Customizing Matlab labels'>Customizing Matlab labels</a> <small>Matlab's text uicontrol is not very customizable, and does not support HTML or Tex formatting. This article shows how to display HTML labels in Matlab and some undocumented customizations...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Have you ever tried to customize the way in which tick labels appear in Matlab plot axes?</p><p>For example, setting the numerical precision of the labels, or adding some short descriptive text (for example, the units)? If you have, then I bet that you have encountered the following dilemma: Once we modify the tick labels (for discussion sake, let&#8217;s assume the Y axis, so this is done by updating the <b>YTickLabel</b> property), then the corresponding <b>YTickLabelMode</b> property changes from &#8216;auto&#8217; to &#8216;manual&#8217; and loses its relationship to the tick values (<b>YTick</b>). So, if we now zoom or pan the plot, our new labels remain unchanged although the tick values have changed, causing much panic and frustration&#8230; If we also set the tick values manually, this solves <i>that</i> problem but leaves us with another: now, when we zoom or pan, we no longer see any ticks or tick labels at all!</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
src="http://UndocumentedMatlab.com/images/PlotLabels_orig.png" alt="Original plot" title="Original plot" width="134" height="143" /> <img
src="http://UndocumentedMatlab.com/images/PlotLabels_1b.png" alt="Manual labels, auto ticks" title="Manual labels, auto ticks" width="134" height="143" /> <img
src="http://UndocumentedMatlab.com/images/PlotLabels_1c.png" alt="Manual labels, manual ticks" title="Manual labels, manual ticks" width="134" height="143" /><p
class="wp-caption-text">Original plot (left)<br
/>Manual labels, auto ticks (center)<br
/>Manual labels, manual ticks (right)</p></div></center></p><p>Of course, we can always trap the zoom and pan callback functions to update the tick labels dynamically while keeping the tick values automatically. This will work for these cases, but we need to do it separately for zoom and pan. Also, if we modify the axes limits explicitly (via the corresponding <b>YLim</b> property) or indirectly (by modifying the displayed plot data), then the callbacks are not called and the labels are not updated.</p><h3 id="solution">The solution &#8211; using a property change listener</h3><p>A better way to solve this problem is to simply trap changes to the displayed tick values, and whenever these occur to call our dedicated function to update the labels according to the new tick values. This can be done by using UDD, or more precisely the <a
target="_blank" href="http://undocumentedmatlab.com/blog/udd-events-and-listeners/">ability to trap update events on any property</a> (in our case, <b>YTick</b>). Such a mechanism was already <a
target="_blank" href="http://undocumentedmatlab.com/blog/continuous-slider-callback/#Property_Listener">demonstrated here</a> in 2010, as one way to achieve continuous slider feedback. The idea is to use the built-in <i><b>handle.listener</b></i> function with the PropertyPostSet event, as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hhAxes = handle<span style="color: #080;">&#40;</span>hAxes<span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% hAxes is the Matlab handle of our axes</span>
hProp = <span style="color: #0000FF;">findprop</span><span style="color: #080;">&#40;</span>hhAxes,<span style="color:#A020F0;">'YTick'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% a schema.prop object</span>
hListener = <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>hhAxes, hProp, <span style="color:#A020F0;">'PropertyPostSet'</span>, @myCallbackFunction<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">setappdata</span><span style="color: #080;">&#40;</span>hAxes, <span style="color:#A020F0;">'YTickListener'</span>, hListener<span style="color: #080;">&#41;</span>;</pre></div></div><p>Note that we have used <i><b>setappdata</b></i> to store the <code>hListener</code> handle in the axes. This ensures that the listener exists for exactly as long as the axes does. If we had not stored this listener handle somewhere, then Matlab would have immediately deleted the listener hook and our callback function would not have been called upon tick value updates. Forgetting to store listener handles is a common pitfall when using them. If you take a look at the <i><b>addlistener</b></i> function&#8217;s code, you will see that it also uses <i><b>setappdata</b></i> after creating the listener, for exactly this reason. Unfortunately, <i><b>addlistsner</b></i> cannot always be used, and I keep forgetting under which circumstances, so I generally use <i><b>handle.listener</b></i> directly as above: It&#8217;s simple enough to use that I find I never really need to use the simple <i><b>addlistener</b></i> wrapper, but you are welcome to try it yourself.</p><p>That&#8217;s all there is to it: Whenever <b>YTick</b> changes its value(s), our callback function (<i>myCallbackFunction</i>) will automatically be called. It is quite simple to set up. While we cannot use TeX in tick labels yet (this will change in the upcoming <a
target="_blank" href="http://undocumentedmatlab.com/blog/matlab-hg2/">HG2</a>), using <i><b>sprintf</b></i> formatting does enable quite a bit of flexibility in formatting the labels. For example, let&#8217;s say I want my tick labels to have the format &#8216;%.1fV&#8217; (i.e., always one decimal, plus the Volts units):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> myCallbackFunction<span style="color: #080;">&#40;</span>hProp,eventData<span style="color: #080;">&#41;</span>    <span style="color: #228B22;">%#ok - hProp is unused</span>
   hAxes = eventData.<span style="">AffectedObject</span>;
   tickValues = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAxes,<span style="color:#A020F0;">'YTick'</span><span style="color: #080;">&#41;</span>;
   newLabels = arrayfun<span style="color: #080;">&#40;</span>@<span style="color: #080;">&#40;</span>value<span style="color: #080;">&#41;</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">sprintf</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'%.1fV'</span>,value<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>, tickValues, <span style="color:#A020F0;">'UniformOutput'</span>,<span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hAxes, <span style="color:#A020F0;">'YTickLabel'</span>, newLabels<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% myCallbackFunction</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 310px"><img
src="http://UndocumentedMatlab.com/images/PlotLabels_2a.png" alt="Manual labels, automatically updated" title="Manual labels, automatically updated" width="134" height="143" /> <img
src="http://UndocumentedMatlab.com/images/PlotLabels_2b.png" alt="Manual labels, automatically updated" title="Manual labels, automatically updated" width="134" height="143" /><p
class="wp-caption-text">Manual labels, automatically updated</p></div></center></p><h3 id="duplicates">Handling duplicate tick labels</h3><p>Of course, &#8216;%.1fV&#8217; may not be a good format when we zoom in to such a degree that the values differ by less than 0.1 &#8211; in this case all the labels will be the same. So let&#8217;s modify our callback function to add extra decimals until the labels become distinct:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> myCallbackFunction<span style="color: #080;">&#40;</span>hProp,eventData<span style="color: #080;">&#41;</span>    <span style="color: #228B22;">%#ok - hProp is unused</span>
   hAxes = eventData.<span style="">AffectedObject</span>;
   tickValues = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>hAxes,<span style="color:#A020F0;">'YTick'</span><span style="color: #080;">&#41;</span>;
&nbsp;
   <span style="color: #228B22;">%newLabels = arrayfun(@(value)(sprintf('%.1fV',value)), tickValues, 'UniformOutput',false);</span>
   digits = <span style="color: #33f;">0</span>;
   labelsOverlap = <span style="color: #0000FF;">true</span>;
   <span style="color: #0000FF;">while</span> labelsOverlap
      <span style="color: #228B22;">% Add another decimal digit to the format until the labels become distinct</span>
      digits = digits + <span style="color: #33f;">1</span>;
      <span style="color: #0000FF;">format</span> = <span style="color: #0000FF;">sprintf</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'%%.%dfV'</span>,digits<span style="color: #080;">&#41;</span>;
      newLabels = arrayfun<span style="color: #080;">&#40;</span>@<span style="color: #080;">&#40;</span>value<span style="color: #080;">&#41;</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">sprintf</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">format</span>,value<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>, tickValues, <span style="color:#A020F0;">'UniformOutput'</span>,<span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
      labelsOverlap = <span style="color: #080;">&#40;</span><span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>newLabels<span style="color: #080;">&#41;</span> &gt; <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">unique</span><span style="color: #080;">&#40;</span>newLabels<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
      <span style="color: #228B22;">% prevent endless loop if the tick values themselves are non-unique</span>
      <span style="color: #0000FF;">if</span> labelsOverlap <span style="color: #F0F;">&amp;&amp;</span> <span style="color: #0000FF;">max</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">diff</span><span style="color: #080;">&#40;</span>tickValues<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>&lt; <span style="color: #33f;">16</span>*<span style="color: #0000FF;">eps</span>
         <span style="color: #0000FF;">break</span>;
      <span style="color: #0000FF;">end</span>
   <span style="color: #0000FF;">end</span>
&nbsp;
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hAxes, <span style="color:#A020F0;">'YTickLabel'</span>, newLabels<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% myCallbackFunction</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 310px"><img
src="http://UndocumentedMatlab.com/images/PlotLabels_3a.png" alt="non-distinct labels" title="non-distinct labels" width="134" height="143" /> <img
src="http://UndocumentedMatlab.com/images/PlotLabels_3b.png" alt="distinct labels" title="distinct labels" width="134" height="143" /><p
class="wp-caption-text">Non-distinct labels &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; distinct labels</p></div></center></pre><h3 id="ticklabelformat"><i>ticklabelformat</i></h3><p>Based on a file that I received from an anonymous reader a few years ago, I have prepared a utility called <i><b>ticklabelformat</b></i> that automates much of the set-up above. Feel free to <a
target="_blank" href="http://www.mathworks.com/matlabcentral/fileexchange/36254-ticklabelformat">download</a> this utility and modify it for your needs - it's quite simple to read and follow. The usage syntax is as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">ticklabelformat<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'y'</span>,<span style="color:#A020F0;">'%.6g V'</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;">% sets y axis on current axes to display 6 significant digits</span>
ticklabelformat<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'xy'</span>,<span style="color:#A020F0;">'%.2f'</span><span style="color: #080;">&#41;</span>   <span style="color: #228B22;">% sets x &amp; y axes on current axes to display 2 decimal digits</span>
ticklabelformat<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'z'</span>,@myCbFcn<span style="color: #080;">&#41;</span>  <span style="color: #228B22;">% sets a function to update the Z tick labels on current axes</span>
ticklabelformat<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'z'</span>,<span style="color: #080;">&#123;</span>@myCbFcn,extraData<span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;">% sets an update function as above, with extra data</span></pre></div></div><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/axes-looseinset-property/' rel='bookmark' title='Axes LooseInset property'>Axes LooseInset property</a> <small>Matlab plot axes have an undocumented LooseInset property that sets empty margins around the axes, and can be set to provide a tighter fit of the axes to their surroundings....</small></li><li><a
href='http://undocumentedmatlab.com/blog/determining-axes-zoom-state/' rel='bookmark' title='Determining axes zoom state'>Determining axes zoom state</a> <small>The information of whether or not an axes is zoomed or panned can easily be inferred from an internal undocumented object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/fig-files-format/' rel='bookmark' title='FIG files format'>FIG files format</a> <small>FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/customizing-matlab-labels/' rel='bookmark' title='Customizing Matlab labels'>Customizing Matlab labels</a> <small>Matlab's text uicontrol is not very customizable, and does not support HTML or Tex formatting. This article shows how to display HTML labels in Matlab and some undocumented customizations...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/setting-axes-tick-labels-format/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Profiling Matlab memory usage</title><link>http://undocumentedmatlab.com/blog/profiling-matlab-memory-usage/</link> <comments>http://undocumentedmatlab.com/blog/profiling-matlab-memory-usage/#comments</comments> <pubDate>Thu, 01 Mar 2012 00:13:04 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[Memory]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Performance]]></category> <category><![CDATA[Pure Matlab]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2768</guid> <description><![CDATA[mtic and mtoc were a couple of undocumented features that enabled users of past Matlab releases to easily profile memory usage.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/matlab-java-memory-leaks-performance/' rel='bookmark' title='Matlab-Java memory leaks, performance'>Matlab-Java memory leaks, performance</a> <small>Internal fields of Java objects may leak memory - this article explains how to avoid this without sacrificing performance. ...</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlabs-internal-memory-representation/' rel='bookmark' title='Matlab&#8217;s internal memory representation'>Matlab&#8217;s internal memory representation</a> <small>Matlab's internal memory structure is explored and discussed. ...</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-mex-in-place-editing/' rel='bookmark' title='Matlab mex in-place editing'>Matlab mex in-place editing</a> <small>Editing Matlab arrays in-place can be an important technique for optimizing calculations. This article shows how to do it using Mex. ...</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></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Anyone who has had experience with real-life applications knows that Memory usage can have a significant impact on the application&#8217;s usability, in aspects such as performance, interactivity, and even (on some lousy memory-management Operating Systems) crashes/hangs.</p><p>In Matlab releases of the past few years, this has been addressed by expanding the information reported by the built-in <i><b>memory</b></i> function. In addition, an undocumented feature was added to the Matlab Profiler that <a
target="_blank" href="http://undocumentedmatlab.com/blog/undocumented-profiler-options/">enables monitoring</a> memory usage.</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><br
/> <img
title="Profile report with memory &amp; JIT info" src="http://undocumentedmatlab.com/images/profile2d_450.png" alt="Profile report with memory &amp; JIT info" width="450" /><img
title="Profile report with memory &amp; JIT info" src="http://undocumentedmatlab.com/images/profile2c_450.png" alt="Profile report with memory &amp; JIT info" width="450" /></p><p><img
title="Profile report with memory &amp; JIT info" src="http://undocumentedmatlab.com/images/profile2.png" alt="Profile report with memory &amp; JIT info" width="416" /><br
/><p
class="wp-caption-text">Profile report with memory &amp; JIT info</p></div></center></p><p>In Matlab release R2008a (but not on newer releases) we could also use a nifty parameter of the undocumented <a
target="_blank" href="http://undocumentedmatlab.com/blog/undocumented-feature-function/"><i><b>feature</b></i> function</a>:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; feature mtic; a=<span style="color: #0000FF;">ones</span><span style="color: #080;">&#40;</span><span style="color: #33f;">100</span><span style="color: #080;">&#41;</span>; feature mtoc
<span style="color: #0000FF;">ans</span> = 
      TotalAllocated<span style="color: #F0F;">:</span> <span style="color: #33f;">84216</span>
          TotalFreed<span style="color: #F0F;">:</span> <span style="color: #33f;">2584</span>
    LargestAllocated<span style="color: #F0F;">:</span> <span style="color: #33f;">80000</span>
           NumAllocs<span style="color: #F0F;">:</span> <span style="color: #33f;">56</span>
            NumFrees<span style="color: #F0F;">:</span> <span style="color: #33f;">43</span>
                Peak<span style="color: #F0F;">:</span> <span style="color: #33f;">81640</span></pre></div></div><p>As can easily be seen in this example, allocating 100<sup>2</sup> doubles requires 80000 bytes of allocation, plus some 4KB others that were allocated (and 2KB freed) within the function <i><b>ones</b></i>. Running the same code line again gives a very similar result, but now there are 80000 more bytes freed when the matrix <code>a</code> is overwritten:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; feature mtic; a=<span style="color: #0000FF;">ones</span><span style="color: #080;">&#40;</span><span style="color: #33f;">100</span><span style="color: #080;">&#41;</span>; feature mtoc
<span style="color: #0000FF;">ans</span> = 
      TotalAllocated<span style="color: #F0F;">:</span> <span style="color: #33f;">84120</span>
          TotalFreed<span style="color: #F0F;">:</span> <span style="color: #33f;">82760</span>
    LargestAllocated<span style="color: #F0F;">:</span> <span style="color: #33f;">80000</span>
           NumAllocs<span style="color: #F0F;">:</span> <span style="color: #33f;">54</span>
            NumFrees<span style="color: #F0F;">:</span> <span style="color: #33f;">49</span>
                Peak<span style="color: #F0F;">:</span> <span style="color: #33f;">81328</span></pre></div></div><p>This is pretty informative and very handy for debugging memory bottlenecks. Unfortunately, starting in R2008b, features mtic and mtoc are no longer supported <i>&#8220;under the current <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/support/tech-notes/1100/1106.html">memory manager</a>&#8220;</i>. Sometime around 2010 the mtic and mtoc features were completely removed. Users of R2008b and newer releases therefore need to use the internal structs returned by the <i><b>memory</b></i> function, and/or use the profiler&#8217;s memory-monitoring feature. If you ask me, using mtic/mtoc was much simpler and easier. I for one miss these features.</p><p>In a related matter, if we wish to monitor Java&#8217;s memory used within Matlab, we are in a bind, because there are no built-in tools to help us. there are several JVM switches that can be turned on in the <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/support/solutions/en/data/1-18I2C/"><i>java.opts</i></a> file: -Xrunhprof[:help]|[:option=value,...], -Xprof, -Xrunprof, -XX:+PrintClassHistogram <a
target="_blank" rel="nofollow" href="http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html">and so on</a>. There are several memory-monitoring (so-called &#8220;heap-walking&#8221;) tools: the standard JDK jconsole, jmap, jhat and jvisualvm (with its useful plugins) provide good basic coverage. MathWorks has <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/support/solutions/en/data/1-3L4JU7/">posted</a> a tutorial on using jconsole with Matlab. There are a number of other third-party tools such as <a
target="_blank" rel="nofollow" href="http://www.khelekore.org/jmp/">JMP</a> (for JVMs 1.5 and earlier) or <a
target="_blank" rel="nofollow" href="http://www.khelekore.org/jmp/tijmp/">TIJMP</a> (for JVM 1.6). Within Matlab, we can use utilities such as <a
target="_blank" rel="nofollow" href="http://www.javamex.com/classmexer/">Classmexer</a> to estimate a particular object&#8217;s size (both shallow and deep referencing), or use <code>java.lang.Runtime.getRuntime()</code>&#8216;s methods (<i>maxMemory(), freeMemory()</i> and <i>totalMemory()</i>) to monitor overall Java memory (<a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/296813#797410">sample usage</a>).</p><p>Specifically in R2011b (but in no other release), we can also use a built-in Java memory monitor. Unfortunately, this simple and yet useful memory monitor was removed in R2012a (or maybe it was just moved to another package and I haven&#8217;t found out where&#8230; <i>yet</i>&#8230;):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">com.<span style="">mathworks</span>.<span style="">xwidgets</span>.<span style="">JavaMemoryMonitor</span>.<span style="">invoke</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 230px"><img
alt="Matlab R2011b's Java memory monitor" src="http://UndocumentedMatlab.com/images/Java_Memory_Monitor.png" title="Matlab R2011b's Java memory monitor" width="159" /><p
class="wp-caption-text">Matlab R2011b's Java memory monitor</p></div></center></p><p>As I have already noted quite often, using undocumented Matlab features and functions carries the risk that they will not be supported in some future Matlab release. Today&#8217;s article is a case in point.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/matlab-java-memory-leaks-performance/' rel='bookmark' title='Matlab-Java memory leaks, performance'>Matlab-Java memory leaks, performance</a> <small>Internal fields of Java objects may leak memory - this article explains how to avoid this without sacrificing performance. ...</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlabs-internal-memory-representation/' rel='bookmark' title='Matlab&#8217;s internal memory representation'>Matlab&#8217;s internal memory representation</a> <small>Matlab's internal memory structure is explored and discussed. ...</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-mex-in-place-editing/' rel='bookmark' title='Matlab mex in-place editing'>Matlab mex in-place editing</a> <small>Editing Matlab arrays in-place can be an important technique for optimizing calculations. This article shows how to do it using Mex. ...</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></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/profiling-matlab-memory-usage/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Types of undocumented Matlab aspects</title><link>http://undocumentedmatlab.com/blog/types-of-undocumented-matlab-aspects/</link> <comments>http://undocumentedmatlab.com/blog/types-of-undocumented-matlab-aspects/#comments</comments> <pubDate>Thu, 24 Nov 2011 18:00:36 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Low risk of breaking in future versions]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Semi-documented feature]]></category> <category><![CDATA[Semi-documented function]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Internal component]]></category> <category><![CDATA[JMI]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[Undocumented property]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2534</guid> <description><![CDATA[This article lists the different types of undocumented/unsupported/hidden aspects in Matlab<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/reasons-for-undocumented-matlab-aspects/' rel='bookmark' title='Reasons for undocumented Matlab aspects'>Reasons for undocumented Matlab aspects</a> <small>There are many reasons for the numerous undocumented aspects in Matlab - this article explains them....</small></li><li><a
href='http://undocumentedmatlab.com/blog/undocumented-cursorbar-object/' rel='bookmark' title='Undocumented cursorbar object'>Undocumented cursorbar object</a> <small>Matlab's internal undocumented graphics.cursorbar object can be used to present dynamic data-tip cross-hairs...</small></li><li><a
href='http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/' rel='bookmark' title='uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager'>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li><li><a
href='http://undocumentedmatlab.com/blog/undocumented-xml-functionality/' rel='bookmark' title='Undocumented XML functionality'>Undocumented XML functionality</a> <small>Matlab's built-in XML-processing functions have several undocumented features that can be used by Java-savvy users...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Why are there so many undocumented aspects in Matlab?</p><p>This is a great question, recently <a
target="_blank" href="http://undocumentedmatlab.com/blog/guide-customization/#comment-61578">asked</a> by a reader of this blog, so I wanted to expand on it in next week&#8217;s article. Before specifying the different reasons, let&#8217;s map the nature of undocumented aspects that we find in Matlab.</p><p>The term <i>undocumented/unsupported</i> (as opposed to <i>mis-documentated</i> or <i>deprecated</i>) actually refers to quite a large number of different types.<br
/> In the following list, the hyperlinks on the list-item titles lead to a list of corresponding articles on this website:</p><ul><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/undocumented-function/">Undocumented functions</a></b><br
/> Matlab functions which appears nowhere in the documentation, are usually built-in functions (do not have an m-file) and can only be inferred from online CSSM posts or usage within one of the Matlab m-functions installed with Matlab (the latter being the usual case). None of these functions is officially supported by MathWorks. <a
target="_blank" href="http://undocumentedmatlab.com/blog/category/mex/">MEX</a> is an important source for such functions.</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/semi-documented-function/">Semi-documented functions</a></b><br
/> Matlab functionality which exists in Matlab m-functions installed with Matlab, but have their main comment separated from the H1 comment line, thereby hiding it from normal view (via Matlab&#8217;s <i><b>help</b></i> function). The H1 comment line itself is simply a standard warning that this function is not officially supported and may change in some future version. To see the actual help comment, simply edit the function (using Matlab&#8217;s <i><b>edit</b></i> function or any text editor) and place a comment sign (%) at the empty line between the H1 comment and the actual help section. The entire help section will then onward be visible via the <i><b>help</b></i> function:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">        <span style="color: #0000FF;">function</span> <span style="color: #080;">&#91;</span>tree, container<span style="color: #080;">&#93;</span> = uitree<span style="color: #080;">&#40;</span><span style="color: #0000FF;">varargin</span><span style="color: #080;">&#41;</span>
        <span style="color: #228B22;">% WARNING: This feature is not supported in MATLAB</span>
        <span style="color: #228B22;">% and the API and functionality may change in a future release.</span>
<span style="color: #0000FF;">fix</span> =&gt;  <span style="color: #228B22;">%</span>
        <span style="color: #228B22;">% UITREE creates a uitree component with hierarchical data in a figure window.</span>
        <span style="color: #228B22;">%   UITREE creates an empty uitree object with default property values in</span>
        <span style="color: #228B22;">%   a figure window.</span>
        <span style="color: #228B22;">%...</span></pre></div></div><p>These functions are not documented in the full documentation (via Matlab&#8217;s <i><b>doc</b></i> function, or online). The odd thing is that some of these functions may appear in the category help output (for example, <i><b>help</b>(&#8216;uitools&#8217;)</i>), and in some cases may even have a fully-visible help section (e.g., <i><b>help</b>(&#8216;setptr&#8217;)</i>), but do not have any online help documentation (<i><b>docsearch</b>(&#8216;setptr&#8217;)</i> fails, and <i><b>doc</b>(&#8216;setptr&#8217;)</i> simply displays the readable help text).</p><p>All these functions are officially unsupported by MathWorks, even when having a readable help section. The rule of thumb appears to be that a Matlab function is supported only if it has online documentation. Note, however, that in some rare cases a documentation discrepancy may be due to a MathWorks documentation error, not to unsupportability&#8230;</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/undocumented-function/">Helper functions</a></b><br
/> Many fully-supported Matlab functions use helper functions that have a specific use in the main (documented) function(s).  Often, these helper functions are tightly-coupled to their documented parents and are useless as stand-alone functions. But quite a few of them have quite useful stand-alone use, as I&#8217;ve already shown in some past articles.</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/undocumented-feature/">Undocumented features</a> and <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/undocumented-property/">properties</a></b><br
/> Features of otherwise-documented Matlab functions, which appear nowhere in the official documentation. You guessed it – these are also not supported by MathWorks&#8230; Like undocumented functions, you can only infer such features by the occasional CSSM post or a reference somewhere in Matlab&#8217;s m-code.</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/semi-documented-feature/">Semi-documented features</a></b><br
/> Features of otherwise-documented Matlab functions, which are documented in a separate section beneath the main help section, and nowhere else (not in the full doc not the online documentation). If you did not know in advance that these features existed, you could only learn of them by manually looking at Matlab&#8217;s m-files (which is what I do in most cases&#8230;).</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/undocumented-property/">Undocumented properties</a></b><br
/> Many Matlab objects have internal properties, which can be retrieved (via Matlab&#8217;s <i><b>get</b></i> function) and/or set (via the <i><b>set</b></i> function) programmatically. All these properties are fully documented. Many objects also possess hidden properties, some of which are very interesting and useful, but which are undocumented and (oh yes) unsupported. Like undocumented features, they can only be inferred from CSSM or existing code. In a recent <a
target="_blank" href="http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/">article</a> I described my <i><b>getundoc</b></i> utility, which lists these undocumented properties of specified objects.</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/internal-component/">Internal Matlab classes</a></b><br
/> Matlab uses a vast array of specialized Java classes to handle everything from algorithms to GUI. These classes are (of course) undocumented/unsupported. They can often be accessed directly from the Matlab Command Window or user m-files. GUI classes can be inferred by inspecting the figure frame&#8217;s Java components, and non-GUI classes can often be inferred from references in Matlab&#8217;s m-files.</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/JMI">Matlab-Java integration</a></b><br
/> Matlab&#8217;s GUI interface, as well as the Java-to-Matlab interface (JMI) is fully undocumented and unsupported. In addition to JMI, there are other mechanisms to run Matlab code from within Java (namely JMI, COM and DDE) &#8211; these are all unsupported and by-and-large undocumented.</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/?s=UDD">Matlab&#8217;s UDD mechanism</a></b><br
/> UDD (Unified Data Definition?) is used extensively in Matlab as the internal object-oriented mechanism for describing object properties and functionalities. We can use UDD for a wide variety of uses. UDD was described in a series of articles here in early 2011.</li></ul><p>Next week I will list the reasons that cause MathWorks to decide whether a particular feature or property should be documented or not.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/reasons-for-undocumented-matlab-aspects/' rel='bookmark' title='Reasons for undocumented Matlab aspects'>Reasons for undocumented Matlab aspects</a> <small>There are many reasons for the numerous undocumented aspects in Matlab - this article explains them....</small></li><li><a
href='http://undocumentedmatlab.com/blog/undocumented-cursorbar-object/' rel='bookmark' title='Undocumented cursorbar object'>Undocumented cursorbar object</a> <small>Matlab's internal undocumented graphics.cursorbar object can be used to present dynamic data-tip cross-hairs...</small></li><li><a
href='http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/' rel='bookmark' title='uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager'>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li><li><a
href='http://undocumentedmatlab.com/blog/undocumented-xml-functionality/' rel='bookmark' title='Undocumented XML functionality'>Undocumented XML functionality</a> <small>Matlab's built-in XML-processing functions have several undocumented features that can be used by Java-savvy users...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/types-of-undocumented-matlab-aspects/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Controlling plot data-tips</title><link>http://undocumentedmatlab.com/blog/controlling-plot-data-tips/</link> <comments>http://undocumentedmatlab.com/blog/controlling-plot-data-tips/#comments</comments> <pubDate>Wed, 14 Sep 2011 20:42:40 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[modemanager]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[Undocumented property]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2432</guid> <description><![CDATA[Data-tips are an extremely useful plotting tool that can easily be controlled programmatically.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/accessing-plot-brushed-data/' rel='bookmark' title='Accessing plot brushed data'>Accessing plot brushed data</a> <small>Plot data brushing can be accessed programmatically using very simple pure-Matlab code...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-linesmoothing-property/' rel='bookmark' title='Plot LineSmoothing property'>Plot LineSmoothing property</a> <small>LineSmoothing is a hidden and undocumented plot line property that creates anti-aliased (smooth unpixelized) lines in Matlab plots...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/com-activex-tips/' rel='bookmark' title='COM/ActiveX tips &amp; tricks'>COM/ActiveX tips &#038; tricks</a> <small>This article describes several little-known tips useful for COM / ActiveX programming in Matlab...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Plot <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/creating_plots/f4-44221.html">data tips</a> are a great visualization aid for Matlab plots. They enable users to interactively click on a plot location and see a tool-tip that contains the clicked location&#8217;s coordinates. The displayed tooltip text is even customizable using documented properties of the <i><b><a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/ref/datacursormode.html">datacursormode</a></b></i> object.</p><p><center><div
class="wp-caption aligncenter" style="width: 441px"><img
alt="plot data tips" src="http://UndocumentedMatlab.com/images/datatips.png" title="plot data tips" width="431" /><p
class="wp-caption-text">plot data tips</p></div></center></p><p>A client has recently asked me to automatically display an attached data-tip to the last data point of a plotted time series of values. The idea was to immediately see what the latest value of the data series is.</p><p>Unfortunately, the official documentation clearly says that:</p><blockquote><p>You place data tips only by clicking data objects on graphs. You cannot place them programmatically (by executing code to position a data cursor).</p></blockquote><p>Well, this has never stopped us before, has it?</p><h3 id="Creating">Creating new data tips</h3><p>Under the hood, data tips use a data-cursor mode, which shares many similarities in behavior and programming code with the other plot modes (zoom, pan, <a
target="_blank" href="http://undocumentedmatlab.com/blog/accessing-plot-brushed-data/">data-brushing</a>, etc.). At any one time, only a single such mode can be active in any figure window (this is a known limitation of the design). The code itself it actually quite complex and handles numerous edge-cases. Understanding it by simply reading the code (under %matlabroot%\toolbox\matlab\graphics\) is actually pretty difficult. A much easier way to understand the programming flow is to liberally distribute breakpoints (start in <i>datacursormode.m</i>) and interactively activate the functionality, then debug the code step-by-step.</p><p>Luckily, it turns out that the code to create a new data-tip is actually quite simple: first get the data-cursor mode object, then create a new data tip using the mode&#8217;s <i>createDatatip()</i> method, update some data-tip properties and finally update the data-tip&#8217;s position:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% First plot the data</span>
hLine = <span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>xdata, ydata<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% First get the figure's data-cursor mode, activate it, and set some of its properties</span>
cursorMode = datacursormode<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>cursorMode, <span style="color:#A020F0;">'enable'</span>,<span style="color:#A020F0;">'on'</span>, <span style="color:#A020F0;">'UpdateFcn'</span>,@setDataTipTxt, <span style="color:#A020F0;">'NewDataCursorOnClick'</span>,<span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;
<span style="color: #228B22;">% Note: the optional @setDataTipTxt is used to customize the data-tip's appearance</span>
&nbsp;
<span style="color: #228B22;">% Note: the following code was adapted from %matlabroot%\toolbox\matlab\graphics\datacursormode.m</span>
<span style="color: #228B22;">% Create a new data tip</span>
hTarget = handle<span style="color: #080;">&#40;</span>hLine<span style="color: #080;">&#41;</span>;
hDatatip = cursorMode.<span style="">createDatatip</span><span style="color: #080;">&#40;</span>hTarget<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Create a copy of the context menu for the datatip:</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip,<span style="color:#A020F0;">'UIContextMenu'</span>,<span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>cursorMode,<span style="color:#A020F0;">'UIContextMenu'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip,<span style="color:#A020F0;">'HandleVisibility'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip,<span style="color:#A020F0;">'Host'</span>,hTarget<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip,<span style="color:#A020F0;">'ViewStyle'</span>,<span style="color:#A020F0;">'datatip'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Set the data-tip orientation to top-right rather than auto</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip,<span style="color:#A020F0;">'OrientationMode'</span>,<span style="color:#A020F0;">'manual'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip,<span style="color:#A020F0;">'Orientation'</span>,<span style="color:#A020F0;">'top-right'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Update the datatip marker appearance</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hDatatip, <span style="color:#A020F0;">'MarkerSize'</span>,<span style="color: #33f;">5</span>, <span style="color:#A020F0;">'MarkerFaceColor'</span>,<span style="color:#A020F0;">'none'</span>, <span style="color: #F0F;">...</span>
              <span style="color:#A020F0;">'MarkerEdgeColor'</span>,<span style="color:#A020F0;">'k'</span>, <span style="color:#A020F0;">'Marker'</span>,<span style="color:#A020F0;">'o'</span>, <span style="color:#A020F0;">'HitTest'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Move the datatip to the right-most data vertex point</span>
position = <span style="color: #080;">&#91;</span>xdata<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#41;</span>,ydata<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#41;</span>,<span style="color: #33f;">1</span>; xdata<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#41;</span>,ydata<span style="color: #080;">&#40;</span><span style="color: #0000FF;">end</span><span style="color: #080;">&#41;</span>,-<span style="color: #33f;">1</span><span style="color: #080;">&#93;</span>;
update<span style="color: #080;">&#40;</span>hDatatip, position<span style="color: #080;">&#41;</span>;</pre></div></div><h3 id="Updating">Updating an existing data tip</h3><p>To modify the appearance of a data-tip, we first need to get access to the <code>hDatatip</code> object that we created earlier, either programmatically, or interactively (or both). Since we can access pre-stored handles only of programmatically-created (not interactively-created) data-tips, we need to use a different method. There are actually two ways to do this:</p><p>The basic way is to search the relevant axes for objects that have <b>Tag</b>=&#8217;DataTipMarker&#8217;. For each data-tip, we will get two such handles: one for the marker (<b>Type</b>=&#8217;line&#8217;) and the other for the text box tooltip (<b>Type</b>=&#8217;text&#8217;). We can use these to update (for example) the marker size, color and style; and the text&#8217;s font, border and colors.</p><p>A better way is to access the <code>graphics.datatip</code> object itself. This can be done using two hidden properties of the <i><b>datacursormode</b></i> object:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Get the list of all data-tips in the current figure</span>
&gt;&gt; cursorMode = datacursormode<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>
cursorMode =
	graphics.<span style="">datacursormanager</span>
&nbsp;
&gt;&gt; cursorMode.<span style="">DataCursors</span>
<span style="color: #0000FF;">ans</span> =
	graphics.<span style="">datatip</span><span style="color: #F0F;">:</span> <span style="color: #33f;">2</span>-by-<span style="color: #33f;">1</span>
&nbsp;
&gt;&gt; cursorMode.<span style="">CurrentDataCursor</span>
<span style="color: #0000FF;">ans</span> =
	graphics.<span style="">datatip</span>
&nbsp;
&gt;&gt; cursorMode.<span style="">CurrentDataCursor</span>.<span style="color: #0000FF;">get</span>
            Annotation<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 hg.<span style="">Annotation</span><span style="color: #080;">&#93;</span>
           DisplayName<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
           HitTestArea<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
          BeingDeleted<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
         ButtonDownFcn<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
              Children<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>2x1 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
              Clipping<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
             CreateFcn<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
             DeleteFcn<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
            BusyAction<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'queue'</span>
      HandleVisibility<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
               HitTest<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
         Interruptible<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                Parent<span style="color: #F0F;">:</span> <span style="color: #33f;">492.005493164063</span>
    SelectionHighlight<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                   Tag<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
                  <span style="color: #0000FF;">Type</span><span style="color: #F0F;">:</span> <span style="color:#A020F0;">'hggroup'</span>
              UserData<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
              Selected<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
             FontAngle<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'normal'</span>
              FontName<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'Helvetica'</span>
              FontSize<span style="color: #F0F;">:</span> <span style="color: #33f;">8</span>
             FontUnits<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'points'</span>
            FontWeight<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'normal'</span>
             EdgeColor<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">0.8</span> <span style="color: #33f;">0.8</span> <span style="color: #33f;">0.8</span><span style="color: #080;">&#93;</span>
       BackgroundColor<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">1</span> <span style="color: #33f;">1</span> <span style="color: #33f;">0.933333333333333</span><span style="color: #080;">&#93;</span>
             TextColor<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">0</span> <span style="color: #33f;">0</span> <span style="color: #33f;">0</span><span style="color: #080;">&#93;</span>
                Marker<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'o'</span>
            MarkerSize<span style="color: #F0F;">:</span> <span style="color: #33f;">5</span>
       MarkerEdgeColor<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'k'</span>
       MarkerFaceColor<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'none'</span>
       MarkerEraseMode<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'normal'</span>
             Draggable<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
                String<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'Date: 01/09/11'</span>  <span style="color:#A020F0;">'Value: 573.24'</span><span style="color: #080;">&#125;</span>
               Visible<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
             StringFcn<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
             UpdateFcn<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
         <span style="color: #0000FF;">UIContextMenu</span><span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">uicontextmenu</span><span style="color: #080;">&#93;</span>
                  Host<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 graph2d.<span style="">lineseries</span><span style="color: #080;">&#93;</span>
           Interpolate<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span></pre></div></div><p>We can see that the returned <code>graphics.datatip</code> object includes properties of both the text-box and the marker, making it easy to modify. Moreover, we can use its aforementioned <i>update</i> method to move the datatip to a different plot position (see example in the code above). In addition, we can also use the self-explanatory <i>getCursorInfo(), getaxes(), makeCurrent(), movetofront()</i> methods, and a few others.</p><h3 id="Properties">Cursor mode and data-tip properties</h3><p>The <code>graphics.datacursormanager</code> and the <code>graphics.datatip</code> objects have several public properties that we can use:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; cursorMode.<span style="color: #0000FF;">get</span>
              Enable<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
    SnapToDataVertex<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
        DisplayStyle<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'datatip'</span>
           UpdateFcn<span style="color: #F0F;">:</span> @setDataTipTxt
              <span style="color: #0000FF;">Figure</span><span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 <span style="color: #0000FF;">figure</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; cursorMode.<span style="">CurrentDataCursor</span>.<span style="color: #0000FF;">get</span>
            Annotation<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 hg.<span style="">Annotation</span><span style="color: #080;">&#93;</span>
           DisplayName<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
           HitTestArea<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
      <span style="color: #F0F;">...</span> <span style="color: #228B22;">% See the list above</span></pre></div></div><p>Both these objects have plenty of additional hidden properties. You can inspect them using my <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object">uiinspect utility</a>. Here is a brief list for reference (R2011b):</p><p><code>graphics.datacursormanager</code>:</p><ul><li>CurrentDataCursor</li><li>DataCursors</li><li>Debug</li><li>DefaultExportVarName</li><li>DefaultPanelPosition</li><li>EnableAxesStacking</li><li>EnableZStacking</li><li>ExternalListeners</li><li>HiddenUpdateFcn</li><li>NewDataCursorOnClick</li><li>OriginalRenderer</li><li>OriginalRendererMode</li><li>PanelDatatipHandle</li><li>PanelHandle</li><li>PanelTextHandle</li><li>UIContextMenu</li><li>UIState</li><li>ZStackMinimum</li></ul><p><code>graphics.datatip</code>:</p><ul><li>ALimInclude</li><li>ApplicationData</li><li>Behavior</li><li>CLimInclude</li><li>DataCursorHandle</li><li>DataManagerHandle</li><li>Debug</li><li>DoThrowStartDragEvent</li><li>EmptyArgUpdateFcn</li><li>EnableAxesStacking</li><li>EnableZStacking</li><li>EraseMode</li><li>EventObject</li><li>ExternalListenerHandles</li><li>HelpTopicKey</li><li>HostAxes</li><li>HostListenerHandles</li><li>IncludeRenderer</li><li>Invalid</li><li>IsDeserializing</li><li>MarkerHandle</li><li>MarkerHandleButtonDownFcn</li><li>Orientation</li><li>OrientationMode</li><li>OrientationPropertyListener</li><li>OriginalDoubleBufferState</li><li>PixelBounds</li><li>PointsOffset</li><li>Position</li><li>SelfListenerHandles</li><li>Serializable</li><li>TextBoxHandle</li><li>TextBoxHandleButtonDownFcn</li><li>Version</li><li>ViewStyle</li><li>XLimInclude</li><li>YLimInclude</li><li>ZLimInclude</li><li>ZStackMinimum</li><li>uistate</li></ul><p>As can be seen, if we really want, we can always use the <b>MarkerHandle</b> or <b>TextBoxHandle</b> directly.</p><h3 id="Deleting">Deleting data tips</h3><p>To delete a specific data-tip, simply call the cursor mode&#8217;s <i>removeDataCursor()</i> method; to delete all data-tips, call its <i>removeAllDataCursors()</i> method:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Delete the current data-tip</span>
cursorMode.<span style="">removeDataCursor</span><span style="color: #080;">&#40;</span>cursorMode.<span style="">CurrentDataCursor</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">% Delete all data-tips</span>
cursorMode.<span style="">removeAllDataCursors</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span></pre></div></div><p>Have you used plot data-tips in some nifty way? If so, please share your experience in a <a
href="http://undocumentedmatlab.com/blog/controlling-plot-data-tips/#respond">comment</a> below.</p><p>p.s. &#8211; did you notice that Java was not mentioned anywhere above? Mode managers use pure-Matlab functionality.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/accessing-plot-brushed-data/' rel='bookmark' title='Accessing plot brushed data'>Accessing plot brushed data</a> <small>Plot data brushing can be accessed programmatically using very simple pure-Matlab code...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-linesmoothing-property/' rel='bookmark' title='Plot LineSmoothing property'>Plot LineSmoothing property</a> <small>LineSmoothing is a hidden and undocumented plot line property that creates anti-aliased (smooth unpixelized) lines in Matlab plots...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/com-activex-tips/' rel='bookmark' title='COM/ActiveX tips &amp; tricks'>COM/ActiveX tips &#038; tricks</a> <small>This article describes several little-known tips useful for COM / ActiveX programming in Matlab...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/controlling-plot-data-tips/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Minimize/maximize figure window</title><link>http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/</link> <comments>http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/#comments</comments> <pubDate>Wed, 18 May 2011 23:08:07 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <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[Undocumented function]]></category> <category><![CDATA[Donn Shull]]></category> <category><![CDATA[JavaFrame]]></category> <category><![CDATA[Undocumented property]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2310</guid> <description><![CDATA[Matlab figure windows can easily be maximized, minimized and restored using a bit of undocumented magic powder<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Over the past couple of years, I posted <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/javaframe/">several articles</a> using the <b>JavaFrame</b> property of the figure handle, which enables access to the GUI&#8217;s underlying Java peer object. Today, I show how using <b>JavaFrame</b> we can solve a very frequent user request on the Matlab CSSM forum.</p><h3 id="Problem">The problem</h3><p>Matlab figures can be maximized, minimized and restored by <em>interactively</em> clicking the corresponding icon (or menu item) on the figure window&#8217;s frame (the title bar). However, we often need to create maximized main-application windows, and wish to save the users the need to manually maximize the window. Moreover, we may sometimes even wish to prevent users from resizing a maximized main window.</p><p>Unfortunately, Matlab does not contain any documented or supported way to <em>programmatically</em> maximize, minimize or restore a figure window.</p><p>This is very strange considering the fact that these are such elementary figure operations. Moreover, these operations are supported internally (and have been for many releases already), as shown below. It is therefore difficult for me to understand why they were not added to the documented Matlab HG wrapper functionality a long time ago. I fail to understand why obscure features such as docking were added to the wrapper, but standard minimization and maximization were not.</p><h3 id="Maximization">Maximization</h3><p><a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/?term=maximize+window">Several solutions</a> have been presented to this problem over the years. Let us start with the pressing question of figure maximization:</p><p>Solutions that rely on documented Matlab features tend to compute the available screen size and resize the figure accordingly. The result is lacking in many respects: it does not account for the taskbar (neither in size nor in location, which is not necessarily at the bottom of the screen); it does not remove the window border as in regular maximized figures; and it often ignores extended desktops (i.e. an attached additional monitor).</p><p>The solutions that do work properly all rely on undocumented features: Some use platform-specific native Windows API in a mex-file (Jan Simon&#8217;s recent <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/31437-windowapi">WindowAPI</a> submission really pushes the limit in this and other regards). Alternately, we can easily use the platform-independent <b>JavaFrame</b>:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; jFrame = <span style="color: #0000FF;">get</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;">'JavaFrame'</span><span style="color: #080;">&#41;</span>
jFrame =
com.<span style="">mathworks</span>.<span style="">hg</span>.<span style="">peer</span>.<span style="">FigurePeer</span>@cdbd96
&nbsp;
&gt;&gt; jFrame.<span style="">setMaximized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% to maximize the figure</span>
&gt;&gt; jFrame.<span style="">setMaximized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% to un-maximize the figure</span></pre></div></div><h3 id="Minimization">Minimization</h3><p>To the best of my knowledge, there are no solutions for minimizing figure windows that use documented Matlab features. Again, this can be done using either native Windows API, or the platform-independent <b>JavaFrame</b>:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; jFrame.<span style="">setMinimized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% to minimize the figure</span>
&gt;&gt; jFrame.<span style="">setMinimized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">false</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% to un-minimize the figure</span></pre></div></div><h3 id="Notes">Usage notes</h3><p><b>Maximized</b> and <b>Minimized</b> are mutually-exclusive, meaning that no more than one of them can be 1 (or true) at any time. This is automatically handled – users only need to be aware that a situation in which a window is both maximized and minimized at the same time is impossible (duh!).</p><p>There are several equivalent manners of setting <code>jFrame</code>&#8216;s <b>Maximized</b> and <b>Minimized</b> property values, and your choice may simply be a matter of aesthetics and personal taste:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Three alternative possibilities of setting Maximized:</span>
jFrame.<span style="">setMaximized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jFrame,<span style="color:#A020F0;">'Maximized'</span>,<span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% note interchangeable 1&lt; =&gt;true, 0&lt; =&gt;false</span>
jFrame.<span style="">handle</span>.<span style="">Maximized</span> = <span style="color: #33f;">1</span>;</pre></div></div><p><code>jFrame</code> follows Java convention: the accessor method that retrieves boolean values is called <i>is&lt;Propname&gt;()</i> instead of <i>get&lt;Propname&gt;</i>. In our case: <i>isMaximized()</i> and <i>isMinimized()</i>:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">flag</span> = jFrame.<span style="">isMinimized</span>;        <span style="color: #228B22;">% Note: isMinimized, not getMinimized</span>
<span style="color: #0000FF;">flag</span> = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>jFrame,<span style="color:#A020F0;">'Minimized'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">flag</span> = jFrame.<span style="">handle</span>.<span style="">Minimized</span>;</pre></div></div><p>In some old Matlab releases, <code>jFrame</code> did not possess the <b>Maximized</b> and <b>Minimized</b> properties, and their associated accessor methods. In this case, use the internal <code>FrameProxy</code> which has always contained them:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; jFrameProxy = jFrame.<span style="">fFigureClient</span>.<span style="">getWindow</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> 
jFrameProxy =
com.<span style="">mathworks</span>.<span style="">hg</span>.<span style="">peer</span>.<span style="">FigureFrameProxy</span>$FigureFrame<span style="color: #080;">&#91;</span>fClientProxyFrame,<span style="color: #33f;">227</span>,<span style="color: #33f;">25</span>,568x502,invalid,layout=java.<span style="">awt</span>.<span style="">BorderLayout</span>,<span style="color: #0000FF;">title</span>=<span style="color: #0000FF;">Figure</span> <span style="color: #33f;">1</span>,resizable,normal,defaultCloseOperation=DO_NOTHING_ON_CLOSE,<span style="color: #F0F;">...</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; <span style="color: #228B22;">% Three alternative possibilities of setting Minimized:</span>
&gt;&gt; jFrameProxy.<span style="">setMinimized</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>jFrameProxy,<span style="color:#A020F0;">'Minimized'</span>,<span style="color: #0000FF;">true</span><span style="color: #080;">&#41;</span>;
&gt;&gt; jFrameProxy.<span style="">handle</span>.<span style="">Minimized</span> = <span style="color: #0000FF;">true</span>;</pre></div></div><p>Using <code>FrameProxy</code> for figure minimization and maximization works correctly on both old and new Matlab releases; using <code>jFrame</code> is slightly simpler but only works on recent Matlab releases. Depending on your needs you may choose to use either of these. They are entirely equivalent.</p><p>When either the <b>Maximized</b> or <b>Minimized</b> properties are changed back to false, the window is restored to regular mode, which is the <code>FrameProxy</code>&#8216;s <b>RestoredLocation</b> and <b>RestoredSize</b>.</p><h3 id="JavaFrame">Use of the JavaFrame property</h3><p>Note that all this relies on the undocumented hidden figure property <b>JavaFrame</b>, which issues a standing warning (since Matlab release R2008a) of becoming obsolete in some future Matlab release (HG2?):</p><div
class="wp_syntax"><div
class="code"><pre style="font-family: monospace;"><span style="color: #000000;">>> jFrame = </span><span style="color: #0000ff;">get</span>(<span style="color: #0000ff;">gcf</span>,<span style="color: #800080;">'JavaFrame'</span>)
<span style="color: #ff0000;">Warning: figure JavaFrame property will be obsoleted in a future release.</span>
<span style="color: #000000;">For more information see the JavaFrame resource on the MathWorks web site.
(Type "warning off MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame" to suppress this warning.) 

jFrame =
com.mathworks.hg.peer.FigurePeer@1ffbad6</span>
</pre></div></div><p>To remove the above warning I have used (note the <i><b>handle</b></i> wrapper, as <a
target="_blank" href="http://undocumentedmatlab.com/blog/detecting-window-focus-events/#comment-2756">suggested</a> by Donn Shull):</p><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><span style="color: #0000FF;">gcf</span><span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'JavaFrame'</span><span style="color: #080;">&#41;</span></pre></div></div><p>If and when <b>JavaFrame</b> does become obsolete in some future Matlab version, be sure to look in this blog for workarounds.</p><p>You may also wish to inform MathWorks on the dedicated webpage that they have set up for specifically this reason (<a
target="_blank" rel="nofollow" href="http://www.mathworks.com/javaframe">http://www.mathworks.com/javaframe</a>), how you are using <b>JavaFrame</b> and why it is important for you. This may help them to decide whether to keep <b>JavaFrame</b> or possibly add the functionality using other means.</p><p>Do you have a smart use for the figure&#8217;s minimization or maximization feature? or another use for <b>JavaFrame</b>? If so, please share your ideas in a <a
target="_blank" href="http://UndocumentedMatlab.com/blog/minimize-maximize-figure-window#respond">comment</a> below.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/disable-entire-figure-window/' rel='bookmark' title='Enable/disable entire figure window'>Enable/disable entire figure window</a> <small>Disabling/enabling an entire figure window is impossible with pure Matlab, but is very simple using the underlying Java. This article explains how....</small></li><li><a
href='http://undocumentedmatlab.com/blog/transparent-matlab-figure-window/' rel='bookmark' title='Transparent Matlab figure window'>Transparent Matlab figure window</a> <small>Matlab figure windows can be made fully or partially transparent/translucent or blurred - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/blurred-matlab-figure-window/' rel='bookmark' title='Blurred Matlab figure window'>Blurred Matlab figure window</a> <small>Matlab figure windows can be blurred using a semi-transparent overlaid window - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/detecting-window-focus-events/' rel='bookmark' title='Detecting window focus events'>Detecting window focus events</a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> <item><title>Datenum performance</title><link>http://undocumentedmatlab.com/blog/datenum-performance/</link> <comments>http://undocumentedmatlab.com/blog/datenum-performance/#comments</comments> <pubDate>Wed, 04 May 2011 18:00:34 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[datenum]]></category> <category><![CDATA[Internal component]]></category> <category><![CDATA[Performance]]></category> <category><![CDATA[Profiler]]></category> <category><![CDATA[Pure Matlab]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2299</guid> <description><![CDATA[The performance of the built-in Matlab function datenum can be significantly improved by using an undocumented internal help function<pre> </pre>Related posts:<ol><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><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/cellfun-undocumented-performance-boost/' rel='bookmark' title='cellfun &#8211; undocumented performance boost'>cellfun &#8211; undocumented performance boost</a> <small>Matlab's built-in cellfun function has an undocumented option to significantly improve performance in some cases....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>A few days ago, a reader on StackOverflow <a
target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/5818583/faster-function-than-datenum-in-matlab">asked</a> whether it is possible to improve the performance of Matlab&#8217;s built-in <i><b>datenum</b></i> function. This question reminded me of a similar case that I answered exactly two years ago, of <a
target="_blank" href="http://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function/">improving the performance of the built-in <i><b>ismember</b></i> function</a>.</p><p>In both cases, the solution to the performance question can be found by simply using Matlab&#8217;s built-in profiler in order to extract just the core processing functionality. It is often found that in a particular situation there is no need for all the input arguments data validity checks, and under some known limitations we can indeed use the core functionality directly.</p><p>In the case of <i><b>ismember</b></i>, it turned out that if we are assured in advance that the input data are sorted non-sparse non-NaN values, then we can use the undocumented built-in helper functions <i><b>ismembc</b></i> or <i><b>ismembc2</b></i> for much-improved performance over the standard <i><b>ismember</b></i>. Both <i><b>ismembc</b></i> and <i><b>ismembc2</b></i> happen to be mex files, although this is not always the case for helper functions.</p><p>Our <i><b>datenum</b></i> case is very similar. It turns out that <i><b>datenum</b></i> uses the undocumented built-in helper function <i><b>dtstr2dtnummx</b></i> for the actual processing &#8211; converting a date from text to floating-point number. As I noted in <a
target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/5818583/faster-function-than-datenum-in-matlab/5823278#5823278">my response</a> to the StackOverflow question, we can directly use this helper function for improved performance: On my particular computer, <i><b>dtstr2dtnummx</b></i> is over 3 times faster than the standard <i><b>datenum</b></i> function:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Fast - using dtstr2dtnummx</span>
&gt;&gt; <span style="color: #0000FF;">tic</span>, <span style="color: #0000FF;">for</span> <span style="color: #0000FF;"><span style="color: #33f;">i</span></span>=<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">1000</span>; <span style="color: #0000FF;">dateNum</span>=dtstr2dtnummx<span style="color: #080;">&#40;</span><span style="color: #080;">&#123;</span><span style="color:#A020F0;">'2010-12-12 12:21:12.123'</span><span style="color: #080;">&#125;</span>,<span style="color:#A020F0;">'yyyy-MM-dd HH:mm:ss'</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">end</span>; <span style="color: #0000FF;">dateNum</span>,<span style="color: #0000FF;">toc</span>
<span style="color: #0000FF;">dateNum</span> =
          <span style="color: #33f;">734484.514722222</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.218423</span> seconds.
&nbsp;
<span style="color: #228B22;">% Slower - using datenum</span>
&gt;&gt; <span style="color: #0000FF;">tic</span>, <span style="color: #0000FF;">for</span> <span style="color: #0000FF;"><span style="color: #33f;">i</span></span>=<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">1000</span>; <span style="color: #0000FF;">dateNum</span>=<span style="color: #0000FF;">datenum</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#123;</span><span style="color:#A020F0;">'2010-12-12 12:21:12.123'</span><span style="color: #080;">&#125;</span>,<span style="color:#A020F0;">'yyyy-mm-dd HH:MM:SS'</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">end</span>; <span style="color: #0000FF;">dateNum</span>,<span style="color: #0000FF;">toc</span>
<span style="color: #0000FF;">dateNum</span> =
          <span style="color: #33f;">734484.514722222</span>   <span style="color: #228B22;">% Same value as dtstr2dtnummx - good!</span>
Elapsed time <span style="color: #0000FF;">is</span> <span style="color: #33f;">0.658352</span> seconds.   <span style="color: #228B22;">% 3x slower than dtstr2dtnummx - bad!</span></pre></div></div><p>While the difference in timing may appear negligible, if you are using this function to parse a text file with thousands of lines, each with its own timestamp, then these seemingly negligible time differences quickly add up. Of course, this only makes sense to do if you find out (using the profiler again) that this date parsing is a performance hotspot in your particular application. It was indeed such a performance hotspot in one of my applications, as it apparently was also for the original poster on StackOverflow.</p><p>Like <i><b>ismembc</b></i>, <i><b>dtstr2dtnummx</b></i> is an internal mex function. On my Windows system it is located in C:\Program Files\Matlab\R2011a\toolbox\matlab\timefun\private\dtstr2dtnummx.mexw32. It will have a different extension non-Windows systems, but you will easily find it in its containing folder.</p><p>To gain access to <i><b>dtstr2dtnummx</b></i>, simply add its folder to the Matlab path using the <i><b>addpath</b></i> function, or copy the dtstr2dtnummx.mexw32 file to another folder that is already on your Matlab path.</p><p>Note that the string format is different between <i><b>dtstr2dtnummx</b></i> and <i><b>datenum</b></i>: In the test case above, <i><b>dtstr2dtnummx</b></i> used <code>'yyyy-MM-dd HH:mm:ss'</code>, while <i><b>datenum</b></i> required <code>'yyyy-<b>mm</b>-dd HH:<b>MM:SS</b>'</code>. I have no idea why MathWorks did not keep consistent formatting strings. But because of this, we need to be extra careful (<a
target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/5831563/matlab-date-format/">example1</a>, <a
target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/5880242/matlab-datenum-generation">example2</a>). If you are interested in finding out how the <i><b>datenum</b></i> format strings translates into a <i><b>dtstr2dtnummx</b></i>, take a look at the helper function <i><b>cnv2icudf</b></i>, which is a very readable m-file located in the same folder as <i><b>dtstr2dtnummx</b></i>.</p><p>To those interested, the folder that contains <i><b>dtstr2dtnummx</b></i> also contains some other interesting date conversion functions, so explore and enjoy!</p><p>Perhaps the main lesson that can be learned from this article, and its <i><b>ismembc</b></i> predecessor of two years ago, is that it is very useful to profile the code for performance hotspots. When such a hotspot is found, don&#8217;t stop your profiling at the built-in Matlab functions &#8211; keep digging in the profiler results and perhaps you&#8217;ll find that you can improve performance by taking an internal shortcut.</p><p>Have you discovered any other performance shortcuts in a built-in Matlab function? If so, please <a
href="http://undocumentedmatlab.com/blog/datenum-performance/#respond">post a comment</a> to tell us all about it.</p><p><pre> </pre>Related posts:<ol><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><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/cellfun-undocumented-performance-boost/' rel='bookmark' title='cellfun &#8211; undocumented performance boost'>cellfun &#8211; undocumented performance boost</a> <small>Matlab's built-in cellfun function has an undocumented option to significantly improve performance in some cases....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/datenum-performance/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>UDD and Java</title><link>http://undocumentedmatlab.com/blog/udd-and-java/</link> <comments>http://undocumentedmatlab.com/blog/udd-and-java/#comments</comments> <pubDate>Wed, 23 Mar 2011 21:04:35 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Listeners]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Donn Shull]]></category> <category><![CDATA[Listener]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2213</guid> <description><![CDATA[UDD provides built-in convenience methods to facilitate the integration of Matlab UDD objects with Java code - this article explains how<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events/' rel='bookmark' title='Matlab callbacks for Java events'>Matlab callbacks for Java events</a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/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/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/findjobj-find-underlying-java-object/' rel='bookmark' title='FindJObj &#8211; find a Matlab component&#8217;s underlying Java object'>FindJObj &#8211; find a Matlab component&#8217;s underlying Java object</a> <small>The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p><i>Once again I welcome Donn Shull, who concludes his series on Matlab&#8217;s undocumented UDD mechanism with a discussion of the UDD-Java relationship.</i></p><h3 id="Introduction">Introduction to the UDD-Java relationship</h3><p>Over the course of this series we have mentioned connections between UDD and Java. In <a
target="_blank" href="http://undocumentedmatlab.com/blog/udd-events-and-listeners/">UDD Events and Listeners</a> we described how in Matlab each Java object can have a UDD companion. In <a
target="_blank" href="http://undocumentedmatlab.com/blog/hierarchical-systems-with-udd/">Hierarchical Systems with UDD</a> we briefly noted that a UDD hierarchy may be passed to Java. This suggests that there is a two way relationship between between UDD and Java.</p><p>In this article we will use some undocumented built-in methods such as <b><i>java</i></b> and <b><i>classhandle</i></b> to explore the UDD-Java relationship. We have used built-in methods for UDD objects before. We have also mentioned the importance of studying code from The MathWorks. When you come across something that looks like it may be a UDD method you can check with the <b><i>which</i></b> command:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">which</span> java -<span style="color: #0000FF;">all</span>
C<span style="color: #F0F;">:</span>\MATLAB\R2010b\toolbox\matlab\general\java.<span style="">m</span>
java <span style="color: #0000FF;">is</span> a built-in method                               <span style="color: #228B22;">% javahandle.com.mathworks.hg.peer.Echo method</span>
java <span style="color: #0000FF;">is</span> a built-in method                               <span style="color: #228B22;">% ui.figure method</span>
java <span style="color: #0000FF;">is</span> a built-in method                               <span style="color: #228B22;">% hg2utils.HGHandle method</span>
java <span style="color: #0000FF;">is</span> a built-in method                               <span style="color: #228B22;">% JavaVisible method</span>
java <span style="color: #0000FF;">is</span> a built-in method                               <span style="color: #228B22;">% hg.figure method</span>
java <span style="color: #0000FF;">is</span> a built-in method                               <span style="color: #228B22;">% hg.GObject method</span>
java <span style="color: #0000FF;">is</span> a built-in method                               <span style="color: #228B22;">% schema.class method</span>
java <span style="color: #0000FF;">is</span> a built-in method                               <span style="color: #228B22;">% handle.handle method</span>
java <span style="color: #0000FF;">is</span> a built-in method                               <span style="color: #228B22;">% schema.method method</span>
C<span style="color: #F0F;">:</span>\MATLAB\R2010b\toolbox\rptgen\rptgen\@sgmltag\java.<span style="">m</span>  <span style="color: #228B22;">% sgmltag method</span></pre></div></div><p>If you find <code>schema.class</code> in the comments for built-in methods, then the method is a general UDD method.</p><h3 id="javahandle">UDD javahandle companions for Java object</h3><p>Whenever a Java class is instantiated in Matlab, it is possible to <a
target="_blank" href="http://undocumentedmatlab.com/blog/udd-events-and-listeners/#Java">create a companion UDD object</a>. The created companion can be in either the <code>javahandle</code> or the <code>javahandle_withcallbacks</code> package. The primary reason for creating the companion object is to avoid <a
rel="nofollow" target="_blank" href="http://mathforum.org/kb/message.jspa?messageID=5950839">memory leaks</a> when attaching a Matlab callback to a callback property. It makes sense in general to use the <code>javahandle_withcallbacks</code> package.</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #228B22;">% creage a java instance and the companion UDD object</span>
&gt;&gt; javaFrame = javax.<span style="">swing</span>.<span style="">JFrame</span>;
&nbsp;
&gt;&gt; <span style="color: #228B22;">% dot notation</span>
&gt;&gt; javaFrameUDD = javaFrame.<span style="">handle</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'CallbackProperties'</span><span style="color: #080;">&#41;</span>;
&nbsp;
&gt;&gt; <span style="color: #228B22;">% or Matlab notation</span>
&gt;&gt; javaFrameUDD = handle<span style="color: #080;">&#40;</span>javaFrame,<span style="color:#A020F0;">'CallbackProperties'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>We can use the built-in <b><i>classhandle</i></b> method to inspect our UDD companion object. This can be used, for example, to obtain a list of the events that the Java class generates:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #228B22;">% use classhandle to list a java classes events</span>
&gt;&gt; jch = javaFrame.<span style="">handle</span>.<span style="">classhandle</span>;
&nbsp;
&gt;&gt; <span style="color: #0000FF;">for</span> index = <span style="color: #33f;">1</span><span style="color: #F0F;">:</span>numel<span style="color: #080;">&#40;</span>jch.<span style="">Events</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span>jch.<span style="">Events</span><span style="color: #080;">&#40;</span>index<span style="color: #080;">&#41;</span>.<span style="">Name</span><span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">end</span>
MouseWheelMoved
MouseClicked
MouseEntered
MouseExited
MousePressed
MouseReleased
WindowGainedFocus
WindowLostFocus
WindowActivated
WindowClosed
WindowClosing
WindowDeactivated
WindowDeiconified
WindowIconified
WindowOpened
ComponentHidden
ComponentMoved
ComponentResized
ComponentShown
MouseDragged
MouseMoved
ComponentAdded
ComponentRemoved
AncestorMoved
AncestorResized
FocusGained
FocusLost
WindowStateChanged
HierarchyChanged
CaretPositionChanged
InputMethodTextChanged
PropertyChange
KeyPressed
KeyReleased
KeyTyped
&nbsp;
&gt;&gt; <span style="color: #228B22;">% Use one of the object's callbacks</span>
&gt;&gt; <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>javaFrameUDD,<span style="color:#A020F0;">'WindowGainedFocusCallback'</span>,@myCallbackFcn<span style="color: #080;">&#41;</span>;</pre></div></div><p>If we do not wish to use callback properties, then we can create our UDD companion in the <code>javahandle</code> package and use <b><i>handle.listener</i></b> to respond to events.</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">javaFrame = javax.<span style="">swing</span>.<span style="">JFrame</span>;
javaFrameUDD = javaFrame.<span style="">handle</span>;
lis = <span style="color: #0000FF;">handle.<span style="">listener</span></span><span style="color: #080;">&#40;</span>javaFrameUDD,<span style="color:#A020F0;">'WindowGainedFocus'</span>,@myCallbackFcn<span style="color: #080;">&#41;</span>;</pre></div></div><h3 id="Passing">Passing UDD objects to Java code</h3><p>You can pass any UDD object to your Java classes in Matlab. Matlab will create a Java bean adapter for the UDD object. The bean adapter created is a subclass of <code>com.MathWorks.jmi.bean.UDDObject</code>. <code>UDDObject</code> implements the Java interfaces <code>com.MathWorks.jmi.bean.DynamicProperties</code>, <code>com.MathWorks.jmi.bean.MTObject</code>, <code>com.MathWorks.jmi.bean.TreeObject</code>, and <code>com.mathworks.services.Browseable</code>.</p><p>The generated bean adapter will have the methods of the parent class the methods of the UDD class, as well as <i>set</i> and <i>get</i> methods for the class properties. To understand how this works, let&#8217;s start with our <code>simple.object</code> and use the <b><i>java</i></b> method to inspect the bean adapter:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; myObj = simple.<span style="">object</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'myObj'</span>, <span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>;
&nbsp;
&gt;&gt; <span style="color: #228B22;">% using dot notation with the java method </span>
&gt;&gt; myObj.<span style="">java</span>.<span style="">getClass</span>
<span style="color: #0000FF;">ans</span> =
<span style="color: #0000FF;">class</span> objectBeanAdapter0
&nbsp;
&gt;&gt; myObj.<span style="">java</span>.<span style="color: #0000FF;">methods</span>
&nbsp;
<span style="color: #0000FF;">Methods</span> <span style="color: #0000FF;">for</span> <span style="color: #0000FF;">class</span> objectBeanAdapter0<span style="color: #F0F;">:</span>
&nbsp;
acquireReference                    createNullMatlabObjectListener      lastDown                            
addBelow                            createNullPropertyChangeListener    left                                
addBrowseableListener               <span style="color: #0000FF;">dialog</span>                              notify                              
addFirstBelow                       <span style="color: #0000FF;">disp</span>                                notifyAll                           
addLeft                             dispose                             objectBeanAdapter0                  
addMatlabObjectListener             equals                              releaseReference                    
addObjectPropertyChangeListener     findProperty                        removeBrowseableListener            
addRight                            firstDown                           removeMatlabObjectListener          
browseableCanHaveChildren           getChildAt                          removeObjectPropertyChangeListener  
browseableChild                     getChildCount                       right                               
browseableChildCount                getClass                            setDirtyFlag                        
browseableChildFetchCount           getClassName                        setDynamicPropertyValue             
browseableChildren                  getDynamicProperties                setName                             
browseableDataObject                getDynamicPropertyValue             setPropertyValue                    
browseableDisplayObject             getIndex                            setThreadSafetyCheckLevel           
browseableHasChildren               getIndexOfChild                     setValue                            
browseableNChildren                 getName                             toString                            
browseableNextNSiblings             getNewInstance                      up                                  
browseableNextSibling               getPropertyValue                    updateCache                         
browseableParent                    getValue                            updateChildCount                    
browseablePrevNSiblings             hashCode                            updateIndex                         
browseablePrevSibling               isDirty                             wait                                
checkThreadSafety                   isLeaf                              
clearDirtyFlag                      isObservable                        
compareTo                           isValid</pre></div></div><p>The parent class has added a large number of methods to the bean adapter for our original class. By looking at the list we can see our <i>dialog</i> and <i>disp</i> methods. There are also <i>getName</i>, <i>setName</i>, <i>getValue</i>, and <i>setValue</i> methods for our classes properties. The rest of the methods were inherited from the base <code>UDDObject</code> superclass. We can use any superclass method directly with the bean adapter object. For example:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; myObj.<span style="">java</span>.<span style="">getPropertyValue</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'Name'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
myObj</pre></div></div><h3 id="Interface">Java interface class</h3><p>To be able to use our UDD object in user-written Java code, we need a Java interface class for it. While we could manually write an interface file, UDD provides a very handy convenience method to automatically create the interface file. For this, we use the <b><i>classhandle</i></b> method again. The <code>schema.class</code> object obtained using <b><i>classhandle</i></b> has a method called <i>createJavaInterface</i> that takes two string arguments: the Java interface classname, and the folder in which to place the interface file. The steps to create and use this interface file are:</p><ol><li>Create and test your UDD class</li><li>Create a Java interface file using <code>schema.class</code>&#8216;s <i>CreateJavaInterface</i></li><li>Modify your UDD class definition file (schema.m) to reference the Java interface file</li><li>Create the Java code that uses your class</li></ol><p>For example, to create a Java interface file for the simple object we created above, use the following commands in Matlab:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">classH = classhandle<span style="color: #080;">&#40;</span>myObj<span style="color: #080;">&#41;</span>;
classH.<span style="">createJavaInterface</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'simpleObjectInterface'</span>,<span style="color: #0000FF;">pwd</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>This will create the following simpleObjectInterface.java file in the current working directory:</p><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> simpleObjectInterface 
       <span style="color: #000000; font-weight: bold;">extends</span> com.<span style="color: #006633;">mathworks</span>.<span style="color: #006633;">jmi</span>.<span style="color: #006633;">bean</span>.<span style="color: #006633;">TreeObject</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">/* Properties */</span>
    <span style="color: #000000; font-weight: bold;">public</span> java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">String</span> getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setName<span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">String</span> value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">double</span> getValue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setValue<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span> value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/* Methods */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> dialog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> disp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>The interface file contains <i>set</i> and <i>get</i> accessor methods for our UDD object properties, and Java prototypes for the UDD methods (in our case, <i>dialog</i> and <i>disp</i>).</p><p>The next step is to modify our class definition file (schema.m) to reference the Java interface file we have created. This modification provides the information that Matlab needs to create the bean adapter that implements the Java interface:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">simpleClass = schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#40;</span>simplePackage, <span style="color:#A020F0;">'object'</span><span style="color: #080;">&#41;</span>;
simpleClass.<span style="">JavaInterfaces</span> = <span style="color: #080;">&#123;</span> <span style="color:#A020F0;">'simpleObjectInterface'</span> <span style="color: #080;">&#125;</span>;</pre></div></div><p>We can verify that the generated bean adapter implements the interface using Java Reflection techniques. As always when we have made changes to the class definition file, we need to use the <b><i>clear classes</i></b> command, and then recreate our objects:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; myObj = simple.<span style="">object</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'myObj'</span>, <span style="color: #0000FF;">pi</span><span style="color: #080;">&#41;</span>
myObj =
  Name<span style="color: #F0F;">:</span> myObj
 Value<span style="color: #F0F;">:</span> <span style="color: #33f;">3.141593</span>
&nbsp;
&gt;&gt; myObjBean = java<span style="color: #080;">&#40;</span>myObj<span style="color: #080;">&#41;</span> 
myObjBean =
  Name<span style="color: #F0F;">:</span> myObj
 Value<span style="color: #F0F;">:</span> <span style="color: #33f;">3.141593</span>
&nbsp;
&gt;&gt; interfaces = myObjBean.<span style="">getClass</span>.<span style="">getInterfaces</span> 
interfaces =
java.<span style="">lang</span>.<span style="color: #0000FF;">Class</span><span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span><span style="color: #F0F;">:</span>
    <span style="color: #080;">&#91;</span>java.<span style="">lang</span>.<span style="color: #0000FF;">Class</span><span style="color: #080;">&#93;</span>
&nbsp;
&gt;&gt; interfaces<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span> 
<span style="color: #0000FF;">ans</span> =
interface simpleObjectInterface</pre></div></div><h3 id="Usage">Using UDD in Java</h3><p>Let&#8217;s create a simple Java class that illustrates passing a UDD object to Java. Here we will just have two methods: The first gets the Value property from a class instance and doubles it; the second launches the class instance dialog:</p><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> accessUDDClass 
<span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">double</span> localValue<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> accessUDDClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doubleValue<span style="color: #009900;">&#40;</span>simpleObjectInterface UDDObj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    localValue <span style="color: #339933;">=</span> UDDObj.<span style="color: #006633;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    UDDObj.<span style="color: #006633;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">*</span>localValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> launchDialog<span style="color: #009900;">&#40;</span>simpleObjectInterface UDDObj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    UDDObj.<span style="color: #006633;">dialog</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>If we have set up the Java compiler and environment variables correctly, we can compile our interface and Java class files from inside Matlab using the system command (alternately, we can compile using any external Java compiler or IDE):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; system<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'javac accessUDDClass.java simpleObjectInterface.java'</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
     <span style="color: #33f;">0</span></pre></div></div><p>Now test our simple Java class with the UDD object created earlier:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; javaObj = accessUDDClass
javaObj =
accessUDDClass@eb9b73
&nbsp;
&gt;&gt; javaObj.<span style="">doubleValue</span><span style="color: #080;">&#40;</span>myObj<span style="color: #080;">&#41;</span>  <span style="color: #228B22;">% pi =&gt; 2*pi</span>
&nbsp;
&gt;&gt; myObj
myObj =
  Name<span style="color: #F0F;">:</span> myObj
 Value<span style="color: #F0F;">:</span> <span style="color: #33f;">6.283185</span></pre></div></div><p>This concludes the UDD series. I would like to thank Yair for his help in preparing and presenting this information.</p><h3 id="Editor">Editor&#8217;s note</h3><p><i>I would like to thank Donn for his enourmously detailed work on UDD, and for preparing it in easy-to-follow articles. I can personally attest to the huge time investment it has taken him. I trully believe he deserves a warm &#8220;thank you&#8221; from the Matlab community. Please visit <a
target="_blank" rel="nofollow" href="http://aetoolbox.com/default.aspx">Donn&#8217;s website</a>, or add a short <a
href="http://UndocumentedMatlab.com/blog/udd-and-java/#respond">comment</a> below.</p><p>In the following weeks, I return to the regular stuff that made this website famous: solving day-to-day Matlab problems using simple undocumented built-in Matlab gems.<br/>- Yair</i></p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events/' rel='bookmark' title='Matlab callbacks for Java events'>Matlab callbacks for Java events</a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/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/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/findjobj-find-underlying-java-object/' rel='bookmark' title='FindJObj &#8211; find a Matlab component&#8217;s underlying Java object'>FindJObj &#8211; find a Matlab component&#8217;s underlying Java object</a> <small>The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/udd-and-java/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Creating a simple UDD class</title><link>http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/</link> <comments>http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/#comments</comments> <pubDate>Wed, 23 Feb 2011 17:29:05 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Guest bloggers]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Donn Shull]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema]]></category> <category><![CDATA[schema.class]]></category> <category><![CDATA[schema.prop]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2130</guid> <description><![CDATA[This article explains how to create and test custom UDD packages, classes and objects<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/extending-a-java-class-with-udd/' rel='bookmark' title='Extending a Java class with UDD'>Extending a Java class with UDD</a> <small>Java classes can easily be extended in Matlab, using pure Matlab code. ...</small></li><li><a
href='http://undocumentedmatlab.com/blog/introduction-to-udd/' rel='bookmark' title='Introduction to UDD'>Introduction to UDD</a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-events-and-listeners/' rel='bookmark' title='UDD Events and Listeners'>UDD Events and Listeners</a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p><i>Once again I welcome guest blogger <a
target="_blank" rel="nofollow" href="http://aetoolbox.com/">Donn Shull</a>, who continues his multi-part series about Matlab&#8217;s undocumented UDD objects.</i></p><h3 id="package">Creating a new UDD package</h3><p>To illustrate the construction of UDD classes with Matlab m-code, let&#8217;s create a simple class belonging to a new simple package. Our class will have two properties: a <b>Name</b> property of type string, and a <b>Value</b> property of type double. This class will have two methods that will illustrate overloading the built-in <i><b>disp</b></i> function, and using a <i>dialog</i> method to present a GUI. Our class will also have one event, to demonstrate UDD event handling.</p><p>To create this simple UDD class we need two directories and five m-files (downloadable <a
href="http://UndocumentedMatlab.com/files/simple.zip">here</a>): The parent directory needs to be a directory on the Matlab path. A subdirectory of the parent directory is named with the symbol @ followed by our UDD package name &#8211; this is the package directory. In this example, the subdirectory is called @simple.</p><p>Within the @simple directory, place a file named <i>schema.m</i>, which is the package definition file. This is a very simple file, that merely calls <i><b>schema.package</b></i> to create a new package called &#8216;simple&#8217;:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> schema<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%SCHEMA simple package definition function.</span>
   schema.<span style="">package</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'simple'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>If you place additional m-files in the package directory they will be called package function files. Those files will have package scope and can be accessed with the notation <code>packagename.functionname</code>. We will not use package functions in this example, so we will only have the schema.m file shown above.</p><h3 id="class">Creating a new UDD class</h3><p>Next, create another subdirectory beneath @simple, named with an @ symbol followed by the UDD class name. In this example we will create the directory @object (i.e., /@simple/@object/). We place four m-files in this directory:</p><p>The first file is yet another schema.m file, which is the class-definition file:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> schema<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%SCHEMA  simple.object class definition function.</span>
&nbsp;
   <span style="color: #228B22;">% Get a handle to the 'simple' package</span>
   simplePackage = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'simple'</span><span style="color: #080;">&#41;</span>;
&nbsp;
   <span style="color: #228B22;">% Create a base UDD object</span>
   simpleClass = schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#40;</span>simplePackage, <span style="color:#A020F0;">'object'</span><span style="color: #080;">&#41;</span>;
&nbsp;
   <span style="color: #228B22;">% Define the class methods:</span>
&nbsp;
   <span style="color: #228B22;">% dialog.m method</span>
   m = schema.<span style="">method</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'dialog'</span><span style="color: #080;">&#41;</span>;
   s = m.<span style="">Signature</span>;
   s.<span style="color: #0000FF;">varargin</span>    = <span style="color:#A020F0;">'off'</span>;
   s.<span style="">InputTypes</span>  = <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'handle'</span><span style="color: #080;">&#125;</span>;
   s.<span style="">OutputTypes</span> = <span style="color: #080;">&#123;</span><span style="color: #080;">&#125;</span>;
&nbsp;
   <span style="color: #228B22;">% disp.m method</span>
   m = schema.<span style="">method</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'disp'</span><span style="color: #080;">&#41;</span>;
   s = m.<span style="">Signature</span>;
   s.<span style="color: #0000FF;">varargin</span>    = <span style="color:#A020F0;">'off'</span>;
   s.<span style="">InputTypes</span>  = <span style="color: #080;">&#123;</span><span style="color:#A020F0;">'handle'</span><span style="color: #080;">&#125;</span>;
   s.<span style="">OutputTypes</span> = <span style="color: #080;">&#123;</span><span style="color: #080;">&#125;</span>;
&nbsp;
   <span style="color: #228B22;">% Define the class properties:</span>
   schema.<span style="">prop</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'Name'</span>, <span style="color:#A020F0;">'string'</span><span style="color: #080;">&#41;</span>;
   schema.<span style="">prop</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'Value'</span>, <span style="color:#A020F0;">'double'</span><span style="color: #080;">&#41;</span>;
&nbsp;
   <span style="color: #228B22;">% Define the class events:</span>
   schema.<span style="">event</span><span style="color: #080;">&#40;</span>simpleClass, <span style="color:#A020F0;">'simpleEvent'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>Here, we used the built-in <i><b>findpackage</b></i> function to identify our base package (<code>simple</code>). Then we used <i><b>schema.class</b></i> to define a new class &#8216;object&#8217; within that base package. We next defined two class methods, two properties and finally an event.</p><h3 id="methods">Defining class methods</h3><p>It is not mandatory to define the method signatures as we have done in our class definition file. If you omit the method signature definitions, Matlab will automatically generate default signatures that will actually work in most applications. However, I believe that it is bad practice to omit the method signature definitions in a class definition file, and there are cases where your classes will not work as you have intended if you omit them.</p><p>Now, place a file named object.m in the @object directory. This file contains the class constructor method, which is executed whenever a new instance object of the <code>simple.object</code> class is created:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> simpleObject = object<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%OBJECT constructor for the simple.object class</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   SIMPLEOBJECT = OBJECT(NAME, VALUE) creates an instance of the</span>
<span style="color: #228B22;">%   simple.object class with the Name property set to NAME and the</span>
<span style="color: #228B22;">%   Value property set VALUE</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   SIMPLEOBJECT = OBJECT(NAME) creates an instance of the simple.object</span>
<span style="color: #228B22;">%   class with the Name property set to NAME. The Value property will be</span>
<span style="color: #228B22;">%   given the default value of 0.</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   SIMPLEOBJECT = OBJECT creates an instance of the simple.object class</span>
<span style="color: #228B22;">%   and executes the simple.object dialog method to open a GUI for editing</span>
<span style="color: #228B22;">%   the Name and Value properties.</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   INPUTS:</span>
<span style="color: #228B22;">%       NAME          : string</span>
<span style="color: #228B22;">%       VALUE         : double</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   OUTPUTS:</span>
<span style="color: #228B22;">%       SIMPLEOBJECT  : simple.object instance</span>
   simpleObject = simple.<span style="">object</span>;
   <span style="color: #0000FF;">switch</span> <span style="color: #0000FF;">nargin</span>
      <span style="color: #0000FF;">case</span> <span style="color: #33f;">0</span>
         simpleObject.<span style="color: #0000FF;">dialog</span>;
      <span style="color: #0000FF;">case</span> <span style="color: #33f;">1</span>
         simpleObject.<span style="">Name</span> = name;
      <span style="color: #0000FF;">case</span> <span style="color: #33f;">2</span>
         simpleObject.<span style="">Name</span> = name;
         simpleObject.<span style="">Value</span> = value;
   <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div><p>The two other m-files in the @object directory will be our class methods &#8211; a single file for each method. In our case they are disp.m and dialog.m:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> <span style="color: #0000FF;">disp</span><span style="color: #080;">&#40;</span>self<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%DISP overloaded object disp method</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   DISP(SELF) or SELF.DISP uses the MATLAB builtin DISP function</span>
<span style="color: #228B22;">%   to display the Name and Value properties of the object.</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   INPUTS:</span>
<span style="color: #228B22;">%       SELF  : simple.object instance</span>
   <span style="color: #0000FF;">builtin</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'disp'</span>, <span style="color: #0000FF;">sprintf</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'  Name: %s\n Value: %f'</span>, self.<span style="">Name</span>, self.<span style="">Value</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
   <span style="color: #228B22;">%Alternative: fprintf('\n  Name: %s\n Value: %f', self.Name, self.Value));</span>
<span style="color: #0000FF;">end</span></pre></div></div><p>And the dialog method (in dialog.m):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> <span style="color: #0000FF;">dialog</span><span style="color: #080;">&#40;</span>self<span style="color: #080;">&#41;</span>
<span style="color: #228B22;">%DIALOG dialog method for simple.object for use by openvar</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   DIALOG(SELF) or SELF.DIALOG where self is the name of the simple.object</span>
<span style="color: #228B22;">%   instance opens a gui to edit the Name and Value properties of self.</span>
<span style="color: #228B22;">%</span>
<span style="color: #228B22;">%   INPUTS:</span>
<span style="color: #228B22;">%       SELF  : simple.object</span>
   dlgValues = <span style="color: #0000FF;">inputdlg</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#123;</span><span style="color:#A020F0;">'Name:'</span>, <span style="color:#A020F0;">'Value:'</span><span style="color: #080;">&#125;</span>, <span style="color:#A020F0;">'simple.object'</span>, <span style="color: #33f;">1</span>, <span style="color: #080;">&#123;</span>self.<span style="">Name</span>, <span style="color: #0000FF;">mat2str</span><span style="color: #080;">&#40;</span>self.<span style="">Value</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">if</span> ~<span style="color: #0000FF;">isempty</span><span style="color: #080;">&#40;</span>dlgValues<span style="color: #080;">&#41;</span>
      self.<span style="">Name</span> = dlgValues<span style="color: #080;">&#123;</span><span style="color: #33f;">1</span><span style="color: #080;">&#125;</span>;
      self.<span style="">Value</span> = <span style="color: #0000FF;">eval</span><span style="color: #080;">&#40;</span>dlgValues<span style="color: #080;">&#123;</span><span style="color: #33f;">2</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>;
   <span style="color: #0000FF;">end</span>
<span style="color: #0000FF;">end</span></pre></div></div><h3 id="testing">Testing our new class</h3><p>Now let&#8217;s test our new class by creating an instance without using any input arguments</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">a = simple.<span style="">object</span></pre></div></div><p>This calls the object&#8217;s constructor method, which launches the input dialog GUI:<br
/><center><div
class="wp-caption aligncenter" style="width: 191px"><img
alt="UDD simple class GUI" src="http://UndocumentedMatlab.com/images/UDD_simple_object_1.jpg" title="UDD simple class GUI" width="181" height="163" /><p
class="wp-caption-text">UDD simple class GUI</p></div></center></p><p>Note the default empty string value for the <b>Name</b> property, and the default zero value for the <b>Value</b> property. In one of the following articles I will show how to control property values. For now let&#8217;s assign &#8216;a&#8217; to <b>Name</b> and 1 to <b>Value</b> using the GUI. Selecting OK updates our object and closes the GUI. Matlab then calls the object&#8217;s <i>disp</i> method to display our object in the command window:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">a = 
  Name<span style="color: #F0F;">:</span> a
 Value<span style="color: #F0F;">:</span> <span style="color: #33f;">1.000000</span></pre></div></div><p>We can reopen our object&#8217;s GUI using three methods: The most obvious is to invoke the <i>dialog</i> method using <code>a.dialog</code> or <code>dialog(a)</code>. Alternately, double click on a in the workspace explorer window &#8211; Matlab will automatically call the built-in <i><b>openvar</b></i> function with the variable name and value as arguments. Which leads us to the third method &#8211; simply call <i><b>openvar</b>(&#8216;a&#8217;, a)</i> directly:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Alternatives for programmatically displaying the GUI</span>
a.<span style="color: #0000FF;">dialog</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% or simply: a.dialog</span>
<span style="color: #0000FF;">dialog</span><span style="color: #080;">&#40;</span>a<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">openvar</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'a'</span>,a<span style="color: #080;">&#41;</span>;</pre></div></div><h3 id="help">Accessing UDD help</h3><p>You may have noticed that in our constructor and method files we have included help text. This is good practice for all Matlab files in general, and UDD is no exception. We can access the UDD class help as follows:</p><div
class="wp_syntax"><div
class="code"><pre class="text" style="font-family:monospace;">&gt; help simple.object
 OBJECT constructor for the simple.object class
&nbsp;
    SIMPLEOBJECT = OBJECT(NAME, VALUE) creates an instance of the 
    simple.object class with the Name property set to NAME and the 
    Value property set VALUE
&nbsp;
    SIMPLEOBJECT = OBJECT(NAME) creates an instance of the simple.object
    class with the Name property set to NAME. The Value property will be
    given the default value of 0.
&nbsp;
    SIMPLEOBJECT = OBJECT creates an instance of the simple.object class 
    and executes the simple.object dialog method to open a GUI for editing
    the Name and Value properties.
&nbsp;
    INPUTS:
        NAME          : string
        VALUE         : double
&nbsp;
    OUTPUTS:
        SIMPLEOBJECT  : simple.object instance
&nbsp;
&gt;&gt; help simple.object.disp
 DISP overloaded object disp method
&nbsp;
    DISP(SELF) or SELF.DISP uses the MATLAB builtin DISP function
    to display the Name and Value properties of the object.
&nbsp;
    INPUTS:
        SELF  : simple.object instance</pre></div></div><p>One of the best ways to learn how Matlab works is to examine code written by the Matlab development team. <i><b>openvar</b></i> is a good example: By looking at it we can see that if a variable is a <i><b>handle</b></i> object and is opaque, then <i><b>openvar</b></i> will check to see if it has a <i>dialog</i> method. If so, it will use that to open the variable for editing. With this information we can guess that MCOS, UDD and even java objects can all launch their own dialog editors simply by having an appropriate <i>dialog</i> method.</p><p>An excellent source of UDD information is available in the Matlab toolbox folders. The base Matlab toolbox contains sixteen different UDD packages to explore. Yummy!</p><p>In the next article of this UDD series we will look at creating hierarchical structures using our <code>simple.object</code> and a unique UDD method.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/extending-a-java-class-with-udd/' rel='bookmark' title='Extending a Java class with UDD'>Extending a Java class with UDD</a> <small>Java classes can easily be extended in Matlab, using pure Matlab code. ...</small></li><li><a
href='http://undocumentedmatlab.com/blog/introduction-to-udd/' rel='bookmark' title='Introduction to UDD'>Introduction to UDD</a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-events-and-listeners/' rel='bookmark' title='UDD Events and Listeners'>UDD Events and Listeners</a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Introduction to UDD</title><link>http://undocumentedmatlab.com/blog/introduction-to-udd/</link> <comments>http://undocumentedmatlab.com/blog/introduction-to-udd/#comments</comments> <pubDate>Wed, 16 Feb 2011 18:00:09 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Guest bloggers]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[Listeners]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Donn Shull]]></category> <category><![CDATA[Internal component]]></category> <category><![CDATA[Listener]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema]]></category> <category><![CDATA[schema.class]]></category> <category><![CDATA[schema.prop]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2036</guid> <description><![CDATA[UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/' rel='bookmark' title='Creating a simple UDD class'>Creating a simple UDD class</a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-events-and-listeners/' rel='bookmark' title='UDD Events and Listeners'>UDD Events and Listeners</a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/hierarchical-systems-with-udd/' rel='bookmark' title='Hierarchical Systems with UDD'>Hierarchical Systems with UDD</a> <small>UDD objects can be grouped in structured hierarchies - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/new-information-on-hg2/' rel='bookmark' title='New information on HG2'>New information on HG2</a> <small>More information on Matlab's new HG2 object-oriented handle-graphics system...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p><i>I would like to welcome guest blogger <a
target="_blank" rel="nofollow" href="http://aetoolbox.com/">Donn Shull</a>. Donn will present a series of articles about UDD classes and objects, on which many undocumented Matlab features and functions are based.</i></p><h3 id="Background">Background on UDD</h3><p>Matlab has used objects for a long time. In R8 (Matlab 5.0), their first user accessible class system was introduced. Andy Register wrote a <a
target="_blank" rel="nofollow" href="http://www.scitechpub.com/catalog/product_info.php?products_id=386">detailed reference</a> on using this system. Although that original system is obsolete, it is still available in R24 (R2010b).</p><p>UDD objects (also referred to as <i>schema</i> objects) were introduced with R12 (Matlab 6.0). UDD has been a foundation platform for a number of core Matlab technologies. MathWorks have consistently maintained that UDD is only meant for internal development and not for Matlab users. So, while UDD has no formal documentation, there are plenty of examples and tools to help us learn about it.</p><p>It is somewhat odd that despite Matlab&#8217;s new object-oriented system (<a
target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/matlab_oop/bri1rtu.html">MCOS</a>)&#8217;s introduction 3 years ago, and the <a
target="_blank" href="http://UndocumentedMatlab.com/blog/tag/hg2/">ongoing concurrent development of HG2</a> classes, the older-technology UDD is still being actively developed, as evidenced by the increasing number of UDD classes in recent releases. More background on the differences between these different sets of classes can be found <a
target="_blank" href="http://UndocumentedMatlab.com/blog/new-information-on-hg2/">here</a>.</p><h3 id="WhyBother">Why should we bother learning UDD?</h3><p>There are some things to consider before deciding if you want to spend the time to learn about the UDD class system:</p><h4 id="Pros">The case against studying UDD classes</h4><ul><li>There is no documentation from The MathWorks for these classes</li><li>You will not get any help from The MathWorks in applying these classes</li><li>The UDD system is now more than a decade old and may be phased out in future Matlab releases (perhaps in HG2?)</li></ul><h4 id="Cons">The case for studying UDD classes</h4><ul><li>UDD is currently the foundation of handle graphics, Java integration, COM, and Simulink</li><li>The m code versions of UDD may be considered a forerunner of the newer MCOS class system</li><li>To avoid memory leaks when using Callbacks in GUI applications you currently need to use UDD</li><li>UDD techniques facilitate Matlab interaction with Java GUIs</li><li>UDD directly supports the Matlab style method invocation as well as dot notation for methods without the need to write subsasgn and subsref routines</li></ul><h3 id="Tools">Tools for Learning about UDD</h3><p>We start by describing some undocumented Matlab tools that will help us investigate and understand UDD classes.</p><ul><li><i><b>findpackage</b></i> &#8211; All UDD Classes are defined as members of a package. findpackage takes the package name as an input argument and returns a schema.package object which provides information about the package</li><li><i><b>findclass</b></i> &#8211; This method of the schema.package object returns a schema.class object of the named class if the class exists in the package</li><li><i><b>classhandle</b></i> &#8211; For a given UDD object <i><b>classhandle</b></i> returns a schema.class object with information about the class. <i><b>classhandle</b></i> and <i><b>findclass</b></i> are two ways of getting the same information about a UDD class. <i><b>findclass</b></i> works with a <i><b>schema.package</b></i> object and a class name and does not require an instance of the class. <i><b>classhandle</b></i> works with an instance of a class</li><li><i><b>findprop</b></i> &#8211; This method of the schema.class object returns a schema.prop object which contains information about the named property</li><li><i><b>findevent</b></i> &#8211; This method of the schema.class object returns a schema.prop object which contains information about the named event</li><li><i><b>handle</b></i> &#8211; handle is a multifaceted and unique term for The MathWorks. There are both UDD and MCOS handle classes. There is a UDD handle package. In terms of the tools we need, <i><b>handle</b></i> is also an undocumented function which converts a numeric handle into a UDD handle object. Depending on your background you may want to think of <i><b>handle</b></i> as a cast operator which casts a numeric handle into a UDD object.</li><li><i><b>methods</b></i> &#8211; This is used to display the methods of an object</li><li><i><b>methodsview</b></i> &#8211; Provides a graphic display of an objects methods</li><li><a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object"><i><b>uiinspect</b></i></a> &#8211; Yair Altman&#8217;s object inspection tool, which can be used for COM, Java and Matlab classes (<i><b>uiinspect</b> will be described in a separate article in the near future</i>).</li></ul><p>Before we apply these tools we need to discuss the basic structure of UDD classes. Let&#8217;s compare them with the newer, well documented MCOS classes:</p><p>MCOS classes can be defined simply as a standalone class or scoped by placing the class in a package or a hierarchy of packages. With UDD, all classes must be defined in a package. UDD Packages are not hierarchical so a UDD package may not contain other packages. UDD classes can always be instantiated with syntax of packageName.className. By default MCOS classes are value classes. With MCOS you can subclass the handle class to create handle classes. UDD classes are handle classes by default, but it is possible to create UDD value classes.</p><h3 id="Exploring">Exploring some important built-in UDD Classes</h3><p>The current versions of Matlab include a number of built-in UDD packages. We will use our new tools to see what we can learn about these packages. Let us begin by inspecting the two packages that form the basis of the UDD class system.</p><h4 id="schema">The schema package</h4><p>The built-in schema package contains the classes for creating user written UDD classes. It also is used to provide meta information about UDD classes. Using <i><b>findpackage</b></i> we will obtain a schema.package object for the schema package and then use it obtain information about the classes it contains:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; pkg = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'schema'</span><span style="color: #080;">&#41;</span>
pkg =
        schema.<span style="">package</span>
&nbsp;
&gt;&gt; pkg.<span style="color: #0000FF;">get</span>
               Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'schema'</span>
    DefaultDatabase<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 handle.<span style="">Database</span><span style="color: #080;">&#93;</span>
            Classes<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>9x1 schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#93;</span>
          Functions<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>0x1 handle<span style="color: #080;">&#93;</span>
        JavaPackage<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
         Documented<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span></pre></div></div><p>Note that here we have used the dot-notation pkg.<i><b>get</b></i> &#8211; we could also have used the Matlab notation <i><b>get</b>(pkg)</i> instead.</p><p>We have now learned that that there are nine classes in the schema package. The information about them in a schema package&#8217;s <b>Classes</b> property. To see the information about individual classes we inspect this property:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; pkg.<span style="">Classes</span><span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>.<span style="color: #0000FF;">get</span>
               Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'class'</span>
            Package<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 schema.<span style="">package</span><span style="color: #080;">&#93;</span>
        Description<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
        AccessFlags<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
             <span style="color: #0000FF;">Global</span><span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
             Handle<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
       Superclasses<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>0x1 handle<span style="color: #080;">&#93;</span>
    SuperiorClasses<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
    InferiorClasses<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
            <span style="color: #0000FF;">Methods</span><span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>4x1 schema.<span style="">method</span><span style="color: #080;">&#93;</span>
         Properties<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>13x1 schema.<span style="">prop</span><span style="color: #080;">&#93;</span>
             Events<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
     JavaInterfaces<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span></pre></div></div><p>Not surprisingly, the first class in the schema.package is &#8216;class&#8217; itself. Here we can see that schema.class has 4 methods and 13 properties. We can also see that the schema.class objects have a <b>Name</b> property. Let&#8217;s use that information to list all the classes in the schema package:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; names = <span style="color: #0000FF;">cell</span><span style="color: #080;">&#40;</span>numel<span style="color: #080;">&#40;</span>pkg.<span style="">Classes</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">for</span> index = <span style="color: #33f;">1</span><span style="color: #F0F;">:</span>numel<span style="color: #080;">&#40;</span>names<span style="color: #080;">&#41;</span>, names<span style="color: #080;">&#123;</span>index<span style="color: #080;">&#125;</span> = pkg.<span style="">Classes</span><span style="color: #080;">&#40;</span>index<span style="color: #080;">&#41;</span>.<span style="">Name</span>; <span style="color: #0000FF;">end</span>;
&gt;&gt; names
names =
    <span style="color:#A020F0;">'class'</span>
    <span style="color:#A020F0;">'method'</span>
    <span style="color:#A020F0;">'signature'</span>
    <span style="color:#A020F0;">'package'</span>
    <span style="color:#A020F0;">'event'</span>
    <span style="color:#A020F0;">'prop'</span>
    <span style="color:#A020F0;">'type'</span>
    <span style="color:#A020F0;">'EnumType'</span>
    <span style="color:#A020F0;">'UserType'</span></pre></div></div><p>These are the base classes for the UDD package schema. To illustrate a different way to get information, let&#8217;s use the <i><b>findclass</b></i> method of schema.package to get information about the schema.prop class:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; p = findclass<span style="color: #080;">&#40;</span>pkg, <span style="color:#A020F0;">'prop'</span><span style="color: #080;">&#41;</span>
p =
        schema.<span style="color: #0000FF;">class</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span>p<span style="color: #080;">&#41;</span>
               Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'prop'</span>
            Package<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 schema.<span style="">package</span><span style="color: #080;">&#93;</span>
        Description<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
        AccessFlags<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
             <span style="color: #0000FF;">Global</span><span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
             Handle<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
       Superclasses<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>0x1 handle<span style="color: #080;">&#93;</span>
    SuperiorClasses<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
    InferiorClasses<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span>
            <span style="color: #0000FF;">Methods</span><span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>2x1 schema.<span style="">method</span><span style="color: #080;">&#93;</span>
         Properties<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>9x1 schema.<span style="">prop</span><span style="color: #080;">&#93;</span>
             Events<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
     JavaInterfaces<span style="color: #F0F;">:</span> <span style="color: #080;">&#123;</span>0x1 <span style="color: #0000FF;">cell</span><span style="color: #080;">&#125;</span></pre></div></div><h4 id="handle">The handle package</h4><p>The second basic UDD package is the handle package. Handle holds a special place in Matlab and has multiple meanings: Handle is a type of Matlab object that is passed by reference; <i><b>handle</b></i> is a function which converts a numeric handle to an object; handle is an abstract object in the new MCOS class system and handle is also a UDD package as well as the default type for UDD objects.</p><p>There is an interesting connection between UDD and MCOS that involves handle. In Matlab releases R12 through R2007b, the UDD handle package had up to 12 classes and did not have any package functions (package functions are functions which are scoped to a package; their calling syntax is [outputs] = packageName.<i>functionName(inputs)</i>).</p><p>Beginning with the formal introduction of MCOS in R2008a, the abstract MCOS class handle was introduced. The MCOS handle class has 12 methods. It also turns out that beginning with R2008a, the UDD handle package has 12 package functions which are the MCOS handle methods.</p><p>The 12 UDD classes in the handle package fall into two groups: The database and transaction classes work with the schema.package to provide a UDD stack mechanism; the listener and family of EventData classes work with schema.event to provide the UDD event mechanism:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; pkg = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'handle'</span><span style="color: #080;">&#41;</span>
pkg =
        schema.<span style="">package</span>
&nbsp;
&gt;&gt; pkg.<span style="color: #0000FF;">get</span>
               Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'handle'</span>
    DefaultDatabase<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 handle.<span style="">Database</span><span style="color: #080;">&#93;</span>
            Classes<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>12x1 schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#93;</span>
          Functions<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>12x1 schema.<span style="">method</span><span style="color: #080;">&#93;</span>
        JavaPackage<span style="color: #F0F;">:</span> <span style="color:#A020F0;">''</span>
         Documented<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
&nbsp;
&gt;&gt; names = <span style="color: #0000FF;">cell</span><span style="color: #080;">&#40;</span>numel<span style="color: #080;">&#40;</span>pkg.<span style="">Classes</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
&gt;&gt; <span style="color: #0000FF;">for</span> index = <span style="color: #33f;">1</span><span style="color: #F0F;">:</span>numel<span style="color: #080;">&#40;</span>names<span style="color: #080;">&#41;</span>, names<span style="color: #080;">&#123;</span>index<span style="color: #080;">&#125;</span> = pkg.<span style="">Classes</span><span style="color: #080;">&#40;</span>index<span style="color: #080;">&#41;</span>.<span style="">Name</span>; <span style="color: #0000FF;">end</span>
&gt;&gt; names
names =
    <span style="color:#A020F0;">'Operation'</span>
    <span style="color:#A020F0;">'transaction'</span>
    <span style="color:#A020F0;">'Database'</span>
    <span style="color:#A020F0;">'EventData'</span>
    <span style="color:#A020F0;">'ClassEventData'</span>
    <span style="color:#A020F0;">'ChildEventData'</span>
    <span style="color:#A020F0;">'ParentEventData'</span>
    <span style="color:#A020F0;">'PropertyEventData'</span>
    <span style="color:#A020F0;">'PropertySetEventData'</span>
    <span style="color:#A020F0;">'listener'</span>
    <span style="color:#A020F0;">'JavaEventData'</span>
    <span style="color:#A020F0;">'subreference__'</span></pre></div></div><h4 id="hg">The hg package</h4><p>Arguably the most important UDD package in Matlab is the handle graphics package hg. Among the built-in UDD packages, hg is unique in several respects. As Matlab has evolved from R12 through R2011a, the number of default classes in the hg package has nearly doubled going from 17 classes to 30 (UDD has a mechanism for automatically defining additional classes as needed during run-time).</p><p>The hg package contains a mixture of Global and non Global classes. These classes return a numeric handle, unless they have been created using package scope. The uitools m-file package provides a great example of extending built-in UDD classes with user written m-file UDD classes.</p><p>The UDD class for a Handle-Graphics object can be obtained either by explicitly creating it with the hg package, or using the <i><b>handle</b></i> function on the numeric handle obtained from normal hg object creation. Using figure as an example, you can either use figh = hg.figure or fig = <i><b>figure</b></i> followed by figh = <i><b>handle</b></i>(fig):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; pkg = findpackage<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'hg'</span><span style="color: #080;">&#41;</span>
pkg =
        schema.<span style="">package</span>
&nbsp;
&gt;&gt; pkg.<span style="color: #0000FF;">get</span>
               Name<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'hg'</span>
    DefaultDatabase<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x1 handle.<span style="">Database</span><span style="color: #080;">&#93;</span>
            Classes<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>30x1 schema.<span style="color: #0000FF;">class</span><span style="color: #080;">&#93;</span>
          Functions<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>0x1 handle<span style="color: #080;">&#93;</span>
        JavaPackage<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'com.mathworks.hg'</span>
         Documented<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">for</span> index = <span style="color: #33f;">1</span><span style="color: #F0F;">:</span>numel<span style="color: #080;">&#40;</span>names<span style="color: #080;">&#41;</span>, names<span style="color: #080;">&#123;</span>index<span style="color: #080;">&#125;</span> = pkg.<span style="">Classes</span><span style="color: #080;">&#40;</span>index<span style="color: #080;">&#41;</span>.<span style="">Name</span>; <span style="color: #0000FF;">end</span>
&gt;&gt; names
names =
    <span style="color:#A020F0;">'GObject'</span>
    <span style="color:#A020F0;">'root'</span>
    <span style="color:#A020F0;">'LegendEntry'</span>
    <span style="color:#A020F0;">'Annotation'</span>
    <span style="color:#A020F0;">'figure'</span>
    <span style="color:#A020F0;">'uimenu'</span>
    <span style="color:#A020F0;">'uicontextmenu'</span>
    <span style="color:#A020F0;">'uicontrol'</span>
    <span style="color:#A020F0;">'uitable'</span>
    <span style="color:#A020F0;">'uicontainer'</span>
    <span style="color:#A020F0;">'hgjavacomponent'</span>
    <span style="color:#A020F0;">'uipanel'</span>
    <span style="color:#A020F0;">'uiflowcontainer'</span>
    <span style="color:#A020F0;">'uigridcontainer'</span>
    <span style="color:#A020F0;">'uitoolbar'</span>
    <span style="color:#A020F0;">'uipushtool'</span>
    <span style="color:#A020F0;">'uisplittool'</span>
    <span style="color:#A020F0;">'uitogglesplittool'</span>
    <span style="color:#A020F0;">'uitoggletool'</span>
    <span style="color:#A020F0;">'axes'</span>
    <span style="color:#A020F0;">'hggroup'</span>
    <span style="color:#A020F0;">'text'</span>
    <span style="color:#A020F0;">'line'</span>
    <span style="color:#A020F0;">'patch'</span>
    <span style="color:#A020F0;">'surface'</span>
    <span style="color:#A020F0;">'rectangle'</span>
    <span style="color:#A020F0;">'light'</span>
    <span style="color:#A020F0;">'image'</span>
    <span style="color:#A020F0;">'hgtransform'</span>
    <span style="color:#A020F0;">'uimcosadapter'</span></pre></div></div><p>So far we have just explored the very basic concepts of UDD. You may well be wondering what the big fuss is about, since the information presented so far does not have any immediately-apparent benefits.</p><p>The following set of articles will describe more advanced topics in UDD usage and customizations, using the building blocks presented today. Hopefully you will quickly understand how using UDD can help achieve some very interesting stuff with Matlab.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/' rel='bookmark' title='Creating a simple UDD class'>Creating a simple UDD class</a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/udd-events-and-listeners/' rel='bookmark' title='UDD Events and Listeners'>UDD Events and Listeners</a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li><li><a
href='http://undocumentedmatlab.com/blog/hierarchical-systems-with-udd/' rel='bookmark' title='Hierarchical Systems with UDD'>Hierarchical Systems with UDD</a> <small>UDD objects can be grouped in structured hierarchies - this article explains how...</small></li><li><a
href='http://undocumentedmatlab.com/blog/new-information-on-hg2/' rel='bookmark' title='New information on HG2'>New information on HG2</a> <small>More information on Matlab's new HG2 object-oriented handle-graphics system...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/introduction-to-udd/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>uisplittool &amp; uitogglesplittool</title><link>http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool/</link> <comments>http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool/#comments</comments> <pubDate>Thu, 09 Dec 2010 00:06:33 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Desktop]]></category> <category><![CDATA[Figure window]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[UI controls]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[Toolbar]]></category> <category><![CDATA[uitools]]></category> <category><![CDATA[uiundo]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=1994</guid> <description><![CDATA[Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool-callbacks/' rel='bookmark' title='uisplittool &amp; uitogglesplittool callbacks'>uisplittool &#038; uitogglesplittool callbacks</a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful toolbar controls - this article explains how to customize their behavior...</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/uiundo-matlab-undocumented-undo-redo-manager/' rel='bookmark' title='uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager'>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li><li><a
href='http://undocumentedmatlab.com/blog/customizing-uiundo/' rel='bookmark' title='Customizing uiundo'>Customizing uiundo</a> <small>This article describes how Matlab's undocumented uiundo undo/redo manager can be customized...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Matlab 7.6 (R2008a) and onward contain a reference to <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> in the javacomponent.m and %matlabroot%/bin/registry/hg.xml files. These are reported as built-in functions by the <i><b>which</b></i> function, although they have no corresponding m-file as other similar built-in functions (note the double &#8216;t&#8217;, as in <i>split-tool</i>):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">which</span> uisplittool
built-in <span style="color: #080;">&#40;</span>C<span style="color: #F0F;">:</span>\Matlab\R2010b\toolbox\matlab\uitools\uisplittool<span style="color: #080;">&#41;</span></pre></div></div><p>These uitools are entirely undocumented, even today (R2010b). They puzzled me for a very long time. An acute reader (Jeremy Raymonds) suggested they are related to toolbars, like other uitools such as the <i><b>uipushtool</b></i> and <i><b>uitoggletool</b></i>. This turned out to be the missing clue that unveiled these useful tools:</p><h3 id="Intro">So what are <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i>?</h3><p>Both <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> are basic Handle-Graphics building blocks used in Matlab toolbars, similarly to the well-documented <i><b>uipushtool</b></i> and <i><b>uitoggletool</b></i>.</p><p><i><b>uisplittool</b></i> presents a simple drop-down, whereas <i><b>uitogglesplittool</b></i> presents a drop-down that is also selectable.</p><p>The Publish and Run controls on the Matlab Editor&#8217;s toolbar are examples of <i><b>uisplittool</b></i>, and so are the Brush / Select-Data control on the figure toolbar, and the plot-selection drop-down on the Matlab Desktop&#8217;s Workspace toolbar:<br
/><center><div
class="wp-caption aligncenter" style="width: 371px"><img
alt="uisplittool in action in the Matlab Desktop" src="http://UndocumentedMatlab.com/images/uisplittool.png" title="uisplittool in action in the Matlab Desktop" width="361" height="221" /><p
class="wp-caption-text"><i><b>uisplittool</b></i> in action in the Matlab Desktop</p></div></center></p><h3 id="Appearance">Adding <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> to a toolbar</h3><p>Adding a <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> to a toolbar is done in a similar manner to adding <i><b>uipushtool</b></i>s and <i><b>uitoggletool</b></i>s:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hToolbar = findall<span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcf</span>,<span style="color:#A020F0;">'tag'</span>,<span style="color:#A020F0;">'FigureToolBar'</span><span style="color: #080;">&#41;</span>;
hUndo=uisplittool<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hToolbar<span style="color: #080;">&#41;</span>;       <span style="color: #228B22;">% uisplittool</span>
hRedo=uitogglesplittool<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hToolbar<span style="color: #080;">&#41;</span>; <span style="color: #228B22;">% uitogglesplittool</span></pre></div></div><p>Like <i><b>uipushtool</b></i> and <i><b>uitoggletool</b></i>, <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> also have unique <strong>Type</strong> property values, &#8216;uisplittool&#8217; and &#8216;uitogglesplittool&#8217; respectively. The handles can also be tested using the built-in <i><b>isa</b></i> function:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">isa</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>hUndo<span style="color: #080;">&#41;</span>,<span style="color:#A020F0;">'uisplittool'</span><span style="color: #080;">&#41;</span>   <span style="color: #228B22;">% or: 'uitogglesplittool'</span>
<span style="color: #0000FF;">ans</span> =
     <span style="color: #33f;">1</span>
&gt;&gt; <span style="color: #0000FF;">class</span><span style="color: #080;">&#40;</span>handle<span style="color: #080;">&#40;</span>hUndo<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
uisplittool</pre></div></div><p>Just as with <i><b>uipushtool</b></i>s and <i><b>uitoggletool</b></i>s, the new buttons have an empty button-face appearance, until we fix their <strong>CData</strong>, <strong>Tooltip</strong> and similar settable properties:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Load the Redo icon</span>
icon = <span style="color: #0000FF;">fullfile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">matlabroot</span>,<span style="color:#A020F0;">'/toolbox/matlab/icons/greenarrowicon.gif'</span><span style="color: #080;">&#41;</span>;
<span style="color: #080;">&#91;</span>cdata,map<span style="color: #080;">&#93;</span> = <span style="color: #0000FF;">imread</span><span style="color: #080;">&#40;</span>icon<span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Convert white pixels into a transparent background</span>
map<span style="color: #080;">&#40;</span><span style="color: #0000FF;">find</span><span style="color: #080;">&#40;</span>map<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>+map<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>+map<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #33f;">3</span><span style="color: #080;">&#41;</span>==<span style="color: #33f;">3</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span> = <span style="color: #0000FF;">NaN</span>;
&nbsp;
<span style="color: #228B22;">% Convert into 3D RGB-space</span>
cdataRedo = ind2rgb<span style="color: #080;">&#40;</span>cdata,map<span style="color: #080;">&#41;</span>;
cdataUndo = cdataRedo<span style="color: #080;">&#40;</span><span style="color: #F0F;">:</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">16</span><span style="color: #F0F;">:</span>-<span style="color: #33f;">1</span><span style="color: #F0F;">:</span><span style="color: #33f;">1</span><span style="color: #080;">&#93;</span>,<span style="color: #F0F;">:</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #228B22;">% Add the icon (and its mirror image = undo) to latest toolbar</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hUndo, <span style="color:#A020F0;">'cdata'</span>,cdataUndo, <span style="color:#A020F0;">'tooltip'</span>,<span style="color:#A020F0;">'undo'</span>,<span style="color:#A020F0;">'Separator'</span>,<span style="color:#A020F0;">'on'</span>, <span style="color: #F0F;">...</span>
           <span style="color:#A020F0;">'ClickedCallback'</span>,<span style="color:#A020F0;">'uiundo(gcbf,'</span><span style="color:#A020F0;">'execUndo'</span><span style="color:#A020F0;">')'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hRedo, <span style="color:#A020F0;">'cdata'</span>,cdataRedo, <span style="color:#A020F0;">'tooltip'</span>,<span style="color:#A020F0;">'redo'</span>, <span style="color: #F0F;">...</span>
           <span style="color:#A020F0;">'ClickedCallback'</span>,<span style="color:#A020F0;">'uiundo(gcbf,'</span><span style="color:#A020F0;">'execRedo'</span><span style="color:#A020F0;">')'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="User-created uisplittool &amp; uitogglesplittool toolbar buttons" src="http://UndocumentedMatlab.com/images/uisplittool2b2.png" title="User-created uisplittool &amp; uitogglesplittool toolbar buttons" width="450" height="107" /><p
class="wp-caption-text">User-created <i><b>uisplittool</b></i> &amp; <i><b>uitogglesplittool</b></i> toolbar buttons</p></div></center></p><p>Note that the controls can be created with these properties in a single command:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hUndo = uisplittool<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'parent'</span>,hToolbar, <span style="color:#A020F0;">'cdata'</span>,cdataRedo, <span style="color: #F0F;">...</span><span style="color: #080;">&#41;</span>;</pre></div></div><h3 id="Arranging">Re-arranging the toolbar controls placement</h3><p>Let us now re-arrange our toolbar buttons. Unfortunately, a bug causes <i><b>uisplittool</b></i>s and <i><b>uitogglesplittool</b></i>s to always be placed flush-left when the toolbar&#8217;s children are re-arranged (anyone at TMW reading this in time for the R2011a bug-parade selection?).</p><p>So, we can&#8217;t re-arrange the buttons at the HG-children level. Luckily, we can re-arrange directly at the Java level (note that until now, the entire discussion of <i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i> was purely Matlab-based):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">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>;
<span style="color: #0000FF;">for</span> buttonId = <span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#41;</span>-<span style="color: #33f;">3</span> <span style="color: #F0F;">:</span> -<span style="color: #33f;">1</span> <span style="color: #F0F;">:</span> <span style="color: #33f;">7</span>  <span style="color: #228B22;">% end-to-front</span>
   jToolbar.<span style="">setComponentZOrder</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#40;</span>buttonId<span style="color: #080;">&#41;</span>, buttonId+<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
jToolbar.<span style="">setComponentZOrder</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#40;</span>end-<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">5</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% Separator</span>
jToolbar.<span style="">setComponentZOrder</span><span style="color: #080;">&#40;</span>jButtons<span style="color: #080;">&#40;</span>end-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>, <span style="color: #33f;">6</span><span style="color: #080;">&#41;</span>;   <span style="color: #228B22;">% Undo</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;">7</span><span style="color: #080;">&#41;</span>;     <span style="color: #228B22;">% Redo</span>
jToolbar.<span style="">revalidate</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="Re-arranged uisplittool &amp; uitogglesplittool toolbar buttons" src="http://UndocumentedMatlab.com/images/uisplittool2c2.png" title="Re-arranged uisplittool &amp; uitogglesplittool toolbar buttons" width="450" height="106" /><p
class="wp-caption-text">Re-arranged <i><b>uisplittool</b></i> &amp; <i><b>uitogglesplittool</b></i> toolbar buttons<br/>(not as simple as it may sound)</p></div></center></p><p>Next week, I will combine the information in this article, with <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/uiundo/">last year&#8217;s articles</a> about <i><b>uiundo</b></i>, and show how we can create a dynamic figure toolbar drop-down of undo/redo events. Here is a preview to whet your appetite:</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="undo/redo buttons implemented using uisplittool" src="http://UndocumentedMatlab.com/images/uisplittool4.png" title="undo/redo buttons implemented using uisplittool" width="450" height="226" /><p
class="wp-caption-text">undo/redo buttons implemented using <i><b>uisplittool</b></i></p></div></center></p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool-callbacks/' rel='bookmark' title='uisplittool &amp; uitogglesplittool callbacks'>uisplittool &#038; uitogglesplittool callbacks</a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful toolbar controls - this article explains how to customize their behavior...</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/uiundo-matlab-undocumented-undo-redo-manager/' rel='bookmark' title='uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager'>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li><li><a
href='http://undocumentedmatlab.com/blog/customizing-uiundo/' rel='bookmark' title='Customizing uiundo'>Customizing uiundo</a> <small>This article describes how Matlab's undocumented uiundo undo/redo manager can be customized...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/uisplittool-uitogglesplittool/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> </channel> </rss>

<!-- W3 Total Cache: Minify debug info:
Engine:             disk: basic
Theme:              b7666
Template:           category
-->
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: undocumentedmatlab.com @ 2012-05-18 22:04:52 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/category/undocumented-function/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      2.454s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1337403890; expires=Sun, 19-May-2013 05:04:50 GMT; path=/
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Sat, 19 May 2012 05:04:52 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Sat, 19 May 2012 06:04:52 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               e390c7cca3f1bdb25e570fc1a8fdfd98
Content-Encoding:   gzip
-->
