<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>Undocumented Matlab &#187; schema.class</title> <atom:link href="http://undocumentedmatlab.com/blog/tag/schemaclass/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Thu, 02 Feb 2012 00:24:18 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.1</generator> <item><title>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/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><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></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/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><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></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>Undocumented cursorbar object</title><link>http://undocumentedmatlab.com/blog/undocumented-cursorbar-object/</link> <comments>http://undocumentedmatlab.com/blog/undocumented-cursorbar-object/#comments</comments> <pubDate>Wed, 29 Sep 2010 18:00:12 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Internal component]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema.class]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=1903</guid> <description><![CDATA[Matlab's internal undocumented graphics.cursorbar object can be used to present dynamic data-tip cross-hairs<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/' rel='bookmark' title='getundoc &#8211; get undocumented object properties'>getundoc &#8211; get undocumented object properties</a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/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><li><a
href='http://undocumentedmatlab.com/blog/types-of-undocumented-matlab-aspects/' rel='bookmark' title='Types of undocumented Matlab aspects'>Types of undocumented Matlab aspects</a> <small>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab...</small></li><li><a
href='http://undocumentedmatlab.com/blog/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></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Every now and then, I stumble on a Matlab feature that looks interesting and potentially useful and has existed for many previous Matlab releases, yet remains undocumented and unsupported. Today I present one such object, Matlab&#8217;s <i><b>graphics.cursorbar</b></i>.</p><p>The <i><b>graphics.cursorbar</b></i> object answers a very basic need that is often encountered in graph exploration: displaying data values together with horizontal/vertical cross-hairs, similarly to <i><b>ginput</b></i>.</p><p>While Matlab has provided the data-cursor mode for a long time, the cross-hair feature is still missing as of R2010b. Many CSSM newsgroup readers have asked about this missing feature. Some recent examples: <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/278992">here</a>, <a
target="_blank" rel="nofollow" href="http://www.mathworks.cn/matlabcentral/newsreader/view_thread/289787">here</a>, and <a
target="_blank" rel="nofollow" href="http://www.mathworks.cn/matlabcentral/newsreader/view_thread/288484">here</a>.</p><h3 id="DataMatrix">DataMatrix</h3><p>To answer this need I have created the <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/16181-datamatrix"><i><b>DataMatrix</b></i> utility</a>, which is available on the Matlab File Exchange:</p><p><center><div
class="wp-caption aligncenter" style="width: 460px"><img
alt="DataMatrix: customizable data tooltip &#038; cross-hairs" src="http://UndocumentedMatlab.com/images/datamatrix.png" title="DataMatrix: customizable data tooltip &#038; cross-hairs" width="450" height="398" /><p
class="wp-caption-text">DataMatrix: customizable data tooltip &#038; cross-hairs</p></div></center></p><p><i><b>DataMatrix</b></i> displays matlab&#8217;s standard data-cursor tooltip together with dotted cross-hairs, both of which move with the mouse pointer. <i><b>DataMatrix</b></i> is actually based mostly on fully-documented stuff: the undocumented aspects are secondary to the main program flow and mostly just ensure old releases compatibility and correct behavior in the presence of some figure modes.</p><h3 id="Cursorbar">graphics.cursorbar</h3><p>When I created <i><b>DataMatrix</b></i> in 2007, I had no idea that <i><b>graphics.cursorbar</b></i> already existed. <i><b>graphics.cursorbar</b></i> is an internal Matlab object, that is undocumented and unsupported. It has several advantages over <i><b>DataMatrix</b></i>, being more customizable in the cross-hairs and data marker, although not enabling to customize the tooltip text nor to present both cross-hairs (only horizontal/vertical, not both). It is one of the earliest examples of Matlab&#8217;s old class system (<i><b>schema</b></i>-based).</p><p>We initialize a <i><b>graphics.cursorbar</b></i> object by supplying an axes (not very useful) or plot-line handle (more useful). The cursorbar handle can be customized using properties such as <b>BottomMarker, TopMarker, CursorLineColor, CursorLineStyle, CursorLineWidth, TargetMarkerSize, TargetMarkerStyle, ShowText, Orientation, Position</b> (Position is a hidden property) etc., as well as the regular HG properties (<b>UserData, Visibility, Parent</b> etc.).</p><p>Once the cursor-bar is created, it can be dragged and moved via the mouse cursor, as the following code snippet and animated gif show:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">t=<span style="color: #33f;">0</span><span style="color: #F0F;">:</span>.01<span style="color: #F0F;">:</span><span style="color: #33f;">7</span>; hp=<span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>t,<span style="color: #0000FF;">sin</span><span style="color: #080;">&#40;</span>t<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
hCursorbar = graphics.<span style="">cursorbar</span><span style="color: #080;">&#40;</span>hp<span style="color: #080;">&#41;</span>; <span style="color: #0000FF;">drawnow</span>
hCursorbar.<span style="">CursorLineColor</span> = <span style="color: #080;">&#91;</span>.9,.3,.6<span style="color: #080;">&#93;</span>; <span style="color: #228B22;">% default=[0,0,0]='k'</span>
hCursorbar.<span style="">CursorLineStyle</span> = <span style="color:#A020F0;">'-.'</span>;       <span style="color: #228B22;">% default='-'</span>
hCursorbar.<span style="">CursorLineWidth</span> = <span style="color: #33f;">2.5</span>;        <span style="color: #228B22;">% default=1</span>
hCursorbar.<span style="">Orientation</span> = <span style="color:#A020F0;">'vertical'</span>;     <span style="color: #228B22;">% =default</span>
hCursorbar.<span style="">TargetMarkerSize</span> = <span style="color: #33f;">12</span>;        <span style="color: #228B22;">% default=8</span>
hCursorbar.<span style="">TargetMarkerStyle</span> = <span style="color:#A020F0;">'o'</span>;      <span style="color: #228B22;">% default='s' (square)</span></pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 310px"><img
alt="Matlab's internal cursorbar object" src="http://UndocumentedMatlab.com/images/colorbar_animated.gif" title="Matlab's internal cursorbar object" width="300" height="225" /><p
class="wp-caption-text">Matlab's internal cursorbar object</p></div></center></p><p>Comments within the internal code (%matlabroot%\toolbox\matlab\graphics\@graphics\@cursorbar\*.m) suggest that <i><b>graphics.cursorbar</b></i> has been around since 2003 at least, although I have not checked such old releases. The presented tooltip resembles one of the old data tips, not one of the modern ones. In addition, as far as I can tell, <i><b>graphics.cursorbar</b></i> is not used within the Matlab code corpus. For these reasons it would not surprise me at all to find that MathWorks will remove this feature in some near future release. Until then &#8211; have fun using it!</p><p>Can you find a good use for <i><b>graphics.cursorbar</b></i>? if so, please let us know by posting a comment <a
href="http://undocumentedmatlab.com/blog/undocumented-cursorbar-object/#respond">below</a>.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/' rel='bookmark' title='getundoc &#8211; get undocumented object properties'>getundoc &#8211; get undocumented object properties</a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/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><li><a
href='http://undocumentedmatlab.com/blog/types-of-undocumented-matlab-aspects/' rel='bookmark' title='Types of undocumented Matlab aspects'>Types of undocumented Matlab aspects</a> <small>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab...</small></li><li><a
href='http://undocumentedmatlab.com/blog/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></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/undocumented-cursorbar-object/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>New information on HG2</title><link>http://undocumentedmatlab.com/blog/new-information-on-hg2/</link> <comments>http://undocumentedmatlab.com/blog/new-information-on-hg2/#comments</comments> <pubDate>Mon, 10 May 2010 22:09:39 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[Handle graphics]]></category> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[HG2]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema.class]]></category> <category><![CDATA[schema.prop]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=1473</guid> <description><![CDATA[More information on Matlab's new HG2 object-oriented handle-graphics system<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/introduction-to-udd/' rel='bookmark' title='Introduction to UDD'>Introduction to UDD</a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-hg2/' rel='bookmark' title='Matlab&#8217;s HG2 mechanism'>Matlab&#8217;s HG2 mechanism</a> <small>HG2 is presumably the next generation of Matlab graphics. This article tries to explore its features....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/' rel='bookmark' title='uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager'>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li><li><a
href='http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/' rel='bookmark' title='Creating a simple UDD class'>Creating a simple UDD class</a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Last week I posted a couple of articles on <a
target="_blank" href="http://undocumentedmatlab.com/blog/undocumented-feature-function/">the undocumented <b><i>feature</i></b> function</a> and Matlab&#8217;s apparent move towards a <a
target="_blank" href="http://undocumentedmatlab.com/blog/matlab-hg2/">class-based Handle-Graphics system</a> called HG2.</p><p>Apparently I caused a bit of a stir&#8230;</p><p>This is normally a weekly blog. But I wanted to share some additional relevant information as well as some interesting tips I received in private communications. Please note that much of the following is speculation or guesswork and may be incorrect or even entirely wacky. Please read the following with more than the usual grain of skepticism&#8230;</p><h3 id="UDD">UDD</h3><p>A bit of historical background: Matlab&#8217;s existing Handle Graphics system is based on UDD (Unified Data Definition?) objects. Prior to Matlab Release 12 (a.k.a. 6.0) back in 2000, Matlab was written exclusively in C and HG and Simulink used differing approaches to objects in the MathWorks codebase. UDD was then added for R12 using C++ code with C wrappers for internal use by the MathWorks developers. UDD enabled a new unified approach for HG and Simulink (recall the major overhaul to the Matlab interface in that release, which also modified the GUI to be Java-based). While the HG handles remained numeric, behind the scenes they relied on the new UDD system, which remained undocumented.</p><p>Matlab users who wished to leverage UDD classes could (and still can) access it via some undocumented interface functions: <i><b>handle, handle.listener, handle.event, classhandle, schema.prop, schema.class, schema.event</b></i> (and other <i><b>schema.*</b></i> functions), <i><b>findprop, findclass, findevent</b></i> and several others. Some of these functions were mentioned in past articles on this blog, and others will perhaps be explained in future articles. You can find numerous mentions and usage examples of UDD in the Matlab codebase that is part of each Matlab installation.</p><p>In /toolbox/matlab/helptools/+helpUtils/@HelpProcess/getHelpText.m we can see a related feature (<i><b>feature</b></i>(&#8216;SearchUUDClassesForHelp&#8217;, flag)) which can apparently be used to allow access to the h1 line and help text for UDD methods. Unfortunately, I have not found any relevant UDD candidates for this. I would be very happy to hear if you know of any objects/methods which have a UDD help section.</p><h3 id="MCOS">MCOS</h3><p>Perhaps Matlab&#8217;s Class Object System (MCOS), <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/97653#247876">first introduced in R14</a> (a.k.a. 7.0, released in 2004) grew out of the UDD beginnings, and perhaps it was developed separately. The fact is that it shared several terms and concepts (&#8220;schema&#8221;, properties meta-data, events) with UDD, although no direct interaction between UDD and MCOS exists, AFAIK.</p><p>As an interesting side-note, MCOS was introduced as an opt-in beta-testing feature in R14SP2 (7.0.4, released in 2005). This beta feature cannot be found in the <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/techdoc/rn/bqsq452.html">official online version of the R14SP2 release notes</a>, but can be found in the hardcover version pages 10-11:<br
/> <q>New syntax and features for creating and working with classes in MATLAB. For R14SP2, these features are at a Beta level. If you are interested in being a Beta tester for these features, see &#8220;Beta Test the MATLAB Class System&#8221; on page 11.</p><p><strong>Beta Test the MATLAB Class System</strong>. MATLAB 7.0.4 includes a Beta version of new syntax and features for working with classes in MATLAB, which simplify and expand object-oriented programming capabilities in MATLAB. Participation in this Beta program is open only to customers who are current<br
/> on their maintenance for MATLAB. Trial passcodes will not be made available for this Beta test. If you are interested in being a Beta tester for these features, register on the MathWorks Web site, at <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/products/beta/r14sp2/signup_newfeatures.html">http://www.mathworks.com/products/beta/r14sp2/signup_newfeatures.html</a>.</q> (needless to say, this webpage was since removed&#8230;)</p><p>The MCOS syntax has changed between releases and was not very stable, until it was formally introduced in R2008a (a.k.a. 7.6, released in 2008). You can look at /toolbox/matlab/iofun/@memmapfile/memmapfile.m to see the MCOS evolution from R14 onward.</p><h3 id="HG2">HG2</h3><p>The new HG2 appears to be a merger of MCOS and UDD, using MCOS infrastructure for UDD classes and properties, finally throwing away the old numeric handles and C wrappers for the more powerful object-oriented approach.</p><p>For the transition period between HG and HG2, there seems to be a dedicated feature: <i><b>feature</b></i>(&#8216;HGtoCOS&#8217;, handle) apparently converts a UDD (&#8220;HG&#8221;) handle into an HG2 (&#8220;COS&#8221;) handle. You can also use <i><b>feature</b></i>(&#8216;HGtoCOS&#8217;, 0) to obtain an MCOS object of the desktop (=handle 0). Here is a sample result on a Matlab 2009 release:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; hFig = <span style="color: #0000FF;">figure</span>
hFig =
     <span style="color: #33f;">1</span>
&nbsp;
&gt;&gt; fmcos = feature<span style="color: #080;">&#40;</span><span style="color:#A020F0;">'HGtoCOS'</span>, hFig<span style="color: #080;">&#41;</span>
fmcos =
&nbsp;
  gbtmcos.<span style="color: #0000FF;">figure</span> handle
&nbsp;
  Package<span style="color: #F0F;">:</span> gbtmcos
&nbsp;
  Properties<span style="color: #F0F;">:</span>
                 Alphamap<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>1x64 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
             BeingDeleted<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'off'</span>
               BusyAction<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'queue'</span>
            ButtonDownFcn<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
                 Children<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>0x1 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
                 Clipping<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'on'</span>
          CloseRequestFcn<span style="color: #F0F;">:</span> <span style="color:#A020F0;">'closereq'</span>
                    Color<span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span><span style="color: #33f;">0.8000</span> <span style="color: #33f;">0.8000</span> <span style="color: #33f;">0.8000</span><span style="color: #080;">&#93;</span>
                 <span style="color: #0000FF;">Colormap</span><span style="color: #F0F;">:</span> <span style="color: #080;">&#91;</span>64x3 <span style="color: #0000FF;">double</span><span style="color: #080;">&#93;</span>
                      <span style="color: #F0F;">...</span>  <span style="color: #080;">&#40;</span><span style="color: #0000FF;">all</span> the regular <span style="color: #0000FF;">figure</span> properties<span style="color: #080;">&#41;</span></pre></div></div><p>Note that in that here, the new object package was called GBTMCOS &#8211; perhaps meaning a GBT version of the MCOS system. This corresponds to the <i><b>feature</b></i>(&#8216;useGBT2&#8242;) that I reported in the <a
target="_blank" href="http://undocumentedmatlab.com/blog/undocumented-feature-function/">features article</a>. I have absolutely no idea what GBT stands for, whether it is a synonym for HG2 or not exactly, and what the differences are between GBT1.5 and GBT2. In any case, in R2010a, the same <i><b>feature</b></i>(&#8216;HGtoCOS&#8217;, handle) code returns a ui.figure object: &#8220;GBTMCOS&#8221; was simply renamed &#8220;UI&#8221;.</p><p>I do not know how to convert an HG2 back to a UDD/HG handle. None of the following appears to work:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; fmcos.<span style="">getdoubleimpl</span>
<span style="color: #0000FF;">ans</span> =
    -<span style="color: #33f;">1</span>
&nbsp;
&gt;&gt; fmcos.<span style="color: #0000FF;">double</span>
<span style="color: #0000FF;">ans</span> =
on
&nbsp;
&gt;&gt; <span style="color: #0000FF;">double</span><span style="color: #080;">&#40;</span>fmcos<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">ans</span> =
    -<span style="color: #33f;">1</span>
&nbsp;
&gt;&gt; handle<span style="color: #080;">&#40;</span>fmcos<span style="color: #080;">&#41;</span>
??? <span style="color: #0000FF;">Error</span> using ==&gt; handle
Cannot convert to handle.</pre></div></div><p>I would love to hear any additional information on these subjects, either anonymously or on record. You can use either a direct mail (see link at the top-right of this page) or the <a
href="#respond">comments section</a>.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/introduction-to-udd/' rel='bookmark' title='Introduction to UDD'>Introduction to UDD</a> <small>UDD classes underlie many of Matlab's handle-graphics objects and functionality. This article introduces these classes....</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-hg2/' rel='bookmark' title='Matlab&#8217;s HG2 mechanism'>Matlab&#8217;s HG2 mechanism</a> <small>HG2 is presumably the next generation of Matlab graphics. This article tries to explore its features....</small></li><li><a
href='http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/' rel='bookmark' title='uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager'>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li><li><a
href='http://undocumentedmatlab.com/blog/creating-a-simple-udd-class/' rel='bookmark' title='Creating a simple UDD class'>Creating a simple UDD class</a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/new-information-on-hg2/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</title><link>http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/</link> <comments>http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/#comments</comments> <pubDate>Thu, 29 Oct 2009 22:11:11 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Figure window]]></category> <category><![CDATA[GUI]]></category> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[UI controls]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Callbacks]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[schema.class]]></category> <category><![CDATA[Toolbar]]></category> <category><![CDATA[uitools]]></category> <category><![CDATA[uiundo]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=688</guid> <description><![CDATA[The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage.<pre> </pre>Related posts:<ol><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><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/uisplittool-uitogglesplittool/' rel='bookmark' title='uisplittool &amp; uitogglesplittool'>uisplittool &#038; uitogglesplittool</a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how...</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></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Whenever we have a Matlab GUI containing user-modifiable controls (edit boxes, sliders, toggle buttons etc.), we may wish to include an undo/redo feature. This would normally be a painful programming task. Luckily, there is an undocumented built-in Matlab support for this functionality via the <b><i>uiundo</i></b> function. Note that <b><i>uiundo</i></b> and its functionality is <u>not</u> Java-based but rather uses Matlab&#8217;s classes and the similarly-undocumented <b><i>schema</i></b>-based object-oriented approach.</p><p>A couple of months ago, I explained <a
target="_blank" href="http://undocumentedmatlab.com/blog/figure-toolbar-components/">how to customize the figure toolbar</a>. In that article, I used the undocumented <b><i>uiundo</i></b> function as a target for the toolbar customization and promised to explain its functionality later. I would now like to explain <b><i>uiundo</i></b> and its usage.</p><p>The <b><i>uiundo</i></b> function is basically an accessor for Matlab&#8217;s built-in undo/redo manager object. It is located in the <i>uitools</i> folder (%MATLABROOT%\toolbox\matlab\uitools) and its <i>@uiundo</i> sub-folder. To use <b><i>uiundo</i></b>, simply define within each uicontrol&#8217;s callback function (where we normally place our application GUI logic) the name of the undo/redo action, what should be done to undo the action, and what should be done if the user wished to redo the action after undoing it. <b><i>uiundo</i></b> then takes care of adding this data to the figure&#8217;s undo/redo options under Edit in the main figure menu.</p><p>For example, let&#8217;s build a simple GUI consisting of a slider that controls the value of an edit box:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">hEditbox = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'edit'</span>, <span style="color:#A020F0;">'position'</span>,<span style="color: #080;">&#91;</span><span style="color: #33f;">20</span>,<span style="color: #33f;">60</span>,<span style="color: #33f;">40</span>,<span style="color: #33f;">40</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#41;</span>; 
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hEditbox, <span style="color:#A020F0;">'Enable'</span>,<span style="color:#A020F0;">'off'</span>, <span style="color:#A020F0;">'string'</span>,<span style="color:#A020F0;">'0'</span><span style="color: #080;">&#41;</span>;
hSlider = <span style="color: #0000FF;">uicontrol</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'style'</span>,<span style="color:#A020F0;">'slider'</span>,<span style="color:#A020F0;">'userdata'</span>,hEditbox<span style="color: #080;">&#41;</span>;
callbackStr = <span style="color:#A020F0;">'set(get(gcbo,'</span><span style="color:#A020F0;">'userdata'</span><span style="color:#A020F0;">'),'</span><span style="color:#A020F0;">'string'</span><span style="color:#A020F0;">',num2str(get(gcbo,'</span><span style="color:#A020F0;">'value'</span><span style="color:#A020F0;">')))'</span>;
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hSlider,<span style="color:#A020F0;">'Callback'</span>,callbackStr<span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 294px"><img
alt="Simple GUI with slider update of a numeric value" src="http://UndocumentedMatlab.com/images/uiundo1.png" title="Simple GUI with slider update of a numeric value" width="284" height="166" /><p
class="wp-caption-text">Simple GUI with slider update of a numeric value</p></div></center></p><p>Now, let&#8217;s attach undo/redo actions to the slider&#8217;s callback. First, place the following in test_uiundo.m:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Main callback function for slider updates</span>
<span style="color: #0000FF;">function</span> test_uiundo<span style="color: #080;">&#40;</span><span style="color: #0000FF;">varargin</span><span style="color: #080;">&#41;</span>
&nbsp;
  <span style="color: #228B22;">% Update the edit box with the new value</span>
  hEditbox = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcbo</span>,<span style="color:#A020F0;">'userdata'</span><span style="color: #080;">&#41;</span>;
  newVal = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcbo</span>,<span style="color:#A020F0;">'value'</span><span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hEditbox,<span style="color:#A020F0;">'string'</span>,<span style="color: #0000FF;">num2str</span><span style="color: #080;">&#40;</span>newVal<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
&nbsp;
  <span style="color: #228B22;">% Retrieve and update the stored previous value</span>
  oldVal = <span style="color: #0000FF;">getappdata</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcbo</span>,<span style="color:#A020F0;">'oldValue'</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>oldVal<span style="color: #080;">&#41;</span>,  oldVal=<span style="color: #33f;">0</span>;  <span style="color: #0000FF;">end</span>
  <span style="color: #0000FF;">setappdata</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gcbo</span>,<span style="color:#A020F0;">'oldValue'</span>,newVal<span style="color: #080;">&#41;</span>;
&nbsp;
  <span style="color: #228B22;">% Prepare an undo/redo action</span>
  cmd.<span style="">Name</span> = <span style="color: #0000FF;">sprintf</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'slider update (%g to %g)'</span>,oldVal,newVal<span style="color: #080;">&#41;</span>;
&nbsp;
  <span style="color: #228B22;">% Note: the following is not enough since it only</span>
  <span style="color: #228B22;">%       updates the slider and not the editbox...</span>
  <span style="color: #228B22;">%cmd.Function        = @set;                  % Redo action</span>
  <span style="color: #228B22;">%cmd.Varargin        = {gcbo,'value',newVal};</span>
  <span style="color: #228B22;">%cmd.InverseFunction = @set;                  % Undo action</span>
  <span style="color: #228B22;">%cmd.InverseVarargin = {gcbo,'value',oldVal};</span>
&nbsp;
  <span style="color: #228B22;">% This takes care of the update problem...</span>
  cmd.<span style="color: #0000FF;">Function</span>        = @internal_update;       <span style="color: #228B22;">% Redo action</span>
  cmd.<span style="color: #0000FF;">Varargin</span>        = <span style="color: #080;">&#123;</span><span style="color: #0000FF;">gcbo</span>,newVal,hEditbox<span style="color: #080;">&#125;</span>;
  cmd.<span style="">InverseFunction</span> = @internal_update;       <span style="color: #228B22;">% Undo action</span>
  cmd.<span style="">InverseVarargin</span> = <span style="color: #080;">&#123;</span><span style="color: #0000FF;">gcbo</span>,oldVal,hEditbox<span style="color: #080;">&#125;</span>;
&nbsp;
  <span style="color: #228B22;">% Register the undo/redo action with the figure</span>
  uiundo<span style="color: #080;">&#40;</span>gcbf,<span style="color:#A020F0;">'function'</span>,cmd<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">% Internal update function to update slider &amp; editbox</span>
<span style="color: #0000FF;">function</span> internal_update<span style="color: #080;">&#40;</span>hSlider,newValue,hEditbox<span style="color: #080;">&#41;</span>
  <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hSlider,<span style="color:#A020F0;">'value'</span>,newValue<span style="color: #080;">&#41;</span>;
  <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hEditbox,<span style="color:#A020F0;">'string'</span>,<span style="color: #0000FF;">num2str</span><span style="color: #080;">&#40;</span>newValue<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span></pre></div></div><p>And now let&#8217;s point the slider&#8217;s callback to our new function:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>hSlider,<span style="color:#A020F0;">'Callback'</span>,@test_uiundo<span style="color: #080;">&#41;</span>;</pre></div></div><p><center><div
class="wp-caption aligncenter" style="width: 294px"><img
alt="Undo/redo functionality integrated in the figure" src="http://UndocumentedMatlab.com/images/uiundo2a.png" title="Undo/redo functionality integrated in the figure" width="284" height="166" /><p
class="wp-caption-text">Undo/redo functionality integrated in the figure</p></div></center></p><p>We can also invoke the current Undo and Redo actions programmatically, by calling <b><i>uiundo</i></b> with the &#8216;execUndo&#8217; and &#8216;execRedo&#8217; arguments:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">uiundo<span style="color: #080;">&#40;</span>hFig,<span style="color:#A020F0;">'execUndo'</span><span style="color: #080;">&#41;</span>;
uiundo<span style="color: #080;">&#40;</span>hFig,<span style="color:#A020F0;">'execRedo'</span><span style="color: #080;">&#41;</span>;</pre></div></div><p>When invoking the current Undo and Redo actions programmatically, we can ensure that this action would be invoked only if it is a specific action that is intended:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">uiundo<span style="color: #080;">&#40;</span>hFig,<span style="color:#A020F0;">'execUndo'</span>,<span style="color:#A020F0;">'Save data'</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">% should equal cmd.Name</span></pre></div></div><p>We can use this approach to attach programmatic undo/redo actions to new toolbar or GUI buttons. The code for this was given in the <a
target="_blank" href="http://undocumentedmatlab.com/blog/figure-toolbar-components/">above-mentioned article</a>. Here is the end-result:</p><p><center><br
/><div
class="wp-caption aligncenter" style="width: 392px"><img
alt="Undo/redo functionality integrated in the figure toolbar" src="http://UndocumentedMatlab.com/images/uiundo5.png" title="Undo/redo functionality integrated in the figure toolbar" width="302" height="199" /><br
/> <br
/> <img
alt="Undo/redo functionality integrated in the figure toolbar" src="http://UndocumentedMatlab.com/images/uiundo6.png" title="Undo/redo functionality integrated in the figure toolbar" width="382" height="221" /><p
class="wp-caption-text">Undo/redo functionality integrated in the figure toolbar</p></div><br
/></center></p><p>In my next post, due next week, I will explore advanced customizations of this functionality.</p><p><pre> </pre>Related posts:<ol><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><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/uisplittool-uitogglesplittool/' rel='bookmark' title='uisplittool &amp; uitogglesplittool'>uisplittool &#038; uitogglesplittool</a> <small>Matlab's undocumented uisplittool and uitogglesplittool are powerful controls that can easily be added to Matlab toolbars - this article explains how...</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></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Displaying hidden handle properties</title><link>http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/</link> <comments>http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/#comments</comments> <pubDate>Tue, 05 May 2009 23:03:55 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Hidden property]]></category> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[JavaFrame]]></category> <category><![CDATA[OuterPosition]]></category> <category><![CDATA[PixelBounds]]></category> <category><![CDATA[schema.class]]></category> <category><![CDATA[schema.prop]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=237</guid> <description><![CDATA[I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li><li><a
href='http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/' rel='bookmark' title='getundoc &#8211; get undocumented object properties'>getundoc &#8211; get undocumented object properties</a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/borderless-button-used-for-plot-properties/' rel='bookmark' title='Borderless button used for plot properties'>Borderless button used for plot properties</a> <small>A borderless button can be used to add unobtrusive functionality to plot axes...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Matlab Handle Graphics (HG) is a great way to manipulate GUI objects. HG handles often have some undocumented hidden properties. One pretty well-known example is the <strong>JavaFrame</strong> property of the figure handle, which enables access to the GUI&#8217;s underlying Java peer object.  We can use hidden properties just like any other handle property, using the built-in <b><i>get</i></b> and <b><i>set</i></b> functions.</p><p>But how can we know about these properties? Here are two methods to do so. Like the hidden properties, these two methods are themselves undocumented&#8230;</p><p>1. use the desktop&#8217;s hidden <strong>HideUndocumented</strong> property:</p><blockquote><pre><span style="color: #000000">set(0,</span><span style="color: #800080">'HideUndocumented','off'</span><span style="color: #000000">);</pre></blockquote><p>From now on, when displaying handle properties using <b><i>get</i></b> and <b><i>set</i></b> you&#8217;ll see the hidden properties.</p><p>Note that some of the properties might display a warning indication:</p><blockquote><pre><span style="color: #000000">>> get(gcf)</span>
	Alphamap = [ (1 by 64) double array]
	BackingStore = on
	CloseRequestFcn = closereq
	Color = [0.8 0.8 0.8]
	Colormap = [ (64 by 3) double array]
	CurrentAxes = []
	CurrentCharacter =
	CurrentKey =
	CurrentModifier = [ (1 by 0) cell array]
	CurrentObject = []
	CurrentPoint = [0 0]
	Dithermap<span style="color: #800000">Warning: figure Dithermap is no longer useful
 with TrueColor displays, and will be removed in a future release.</span>
 = [ (64 by 3) double array]
        ...
</pre></blockquote><p>2. Access the properties&#8217; definition in the handle&#8217;s class definition:</p><blockquote><pre><span style="color: #000000">>> ch = classhandle(handle(gcf));
>> props = get(ch,</span><span style="color: #800080">'Properties'</span><span style="color: #000000">);
>> propsVisibility = get(props,</span><span style="color: #800080">'Visible'</span><span style="color: #000000">)';
>> hiddenProps = props(strcmp(propsVisibility,</span><span style="color: #800080">'off'</span><span style="color: #000000">));
>> sort(get(hiddenProps,</span><span style="color: #800080">'Name'</span><span style="color: #000000">))</span>
ans =
    'ALimInclude'
    'ActivePositionProperty'
    'ApplicationData'
    'BackingStore'
    'Behavior'
    'CLimInclude'
    'CurrentKey'
    'CurrentModifier'
    'Dithermap'
    'DithermapMode'
    'ExportTemplate'
    'HelpFcn'
    'HelpTopicKey'
    'HelpTopicMap'
    'IncludeRenderer'
    'JavaFrame'
    'OuterPosition'
    'PixelBounds'
    'PrintTemplate'
    'Serializable'
    'ShareColors'
    'UseHG2'
    'WaitStatus'
    'XLimInclude'
    'YLimInclude'
    'ZLimInclude'
</pre></blockquote><p>Different HG handles have different hidden properties. Not all these properties are useful. For example, I have found the <strong>PixelBounds</strong> property to be problematic &#8211; (it sometimes reports incorrect values!). Other properties (like <strong>Dithermap</strong> or <strong>ShareColors</strong>) are deprecated and display a warning wherever they are accessed.</p><p>But every so often we find a hidden property that can be of some actual benefit. Let&#8217;s take the figure handle&#8217;s <strong>OuterPosition</strong> property for example. It provides the figure&#8217;s external position values, including the space used by the window frame, toolbars etc., whereas the regular documented <strong>Position</strong> property only reports the <b>internal</b> bounds:</p><blockquote><pre><span style="color: #000000">>> get(gcf,</span><span style="color: #800080">'pos'</span>)
ans =
   232   246   560   420
<span style="color: #000000">>> get(gcf,</span><span style="color: #800080">'outer'</span>)
ans =
   228   242   568   502
</pre></blockquote><p>In future posts I will sometimes use such hidden properties. You can find the latest list by looking at this blog&#8217;s <a
href="http://undocumentedmatlab.com/blog/category/Hidden-property/" target="_blank">&#8220;Hidden property&#8221;</a> category page.</p><p>Note: Like the rest of Matlab&#8217;s undocumented items, all hidden properties are undocumented, unsupported and may well change in future Matlab releases so use them with care.</p><p>Did you find any useful hidden property? If so, then please leave your finding in the comments section below.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/udd-properties/' rel='bookmark' title='UDD Properties'>UDD Properties</a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li><li><a
href='http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/' rel='bookmark' title='getundoc &#8211; get undocumented object properties'>getundoc &#8211; get undocumented object properties</a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-liminclude-properties/' rel='bookmark' title='Plot LimInclude properties'>Plot LimInclude properties</a> <small>The plot objects' XLimInclude, YLimInclude, ZLimInclude, ALimInclude and CLimInclude properties are an important feature, that has both functional and performance implications....</small></li><li><a
href='http://undocumentedmatlab.com/blog/borderless-button-used-for-plot-properties/' rel='bookmark' title='Borderless button used for plot properties'>Borderless button used for plot properties</a> <small>A borderless button can be used to add unobtrusive functionality to plot axes...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/displaying-hidden-handle-properties/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> </channel> </rss>

<!-- W3 Total Cache: Minify debug info:
Engine:             disk: basic
Theme:              b7666
Template:           tag
-->
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: undocumentedmatlab.com @ 2012-02-04 03:39:09 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/tag/schemaclass/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      1.667s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1328351948; expires=Sun, 03-Feb-2013 10:39:08 GMT; path=/
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Sat, 04 Feb 2012 10:39:09 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Sat, 04 Feb 2012 11:39:09 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               dec6b301558a8234110d1acbfa2e2d87
Content-Encoding:   gzip
-->
