<?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; Semi-documented feature</title> <atom:link href="http://undocumentedmatlab.com/blog/tag/semi-documented-feature/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Wed, 08 Feb 2012 18:40:25 +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>Types of undocumented Matlab aspects</title><link>http://undocumentedmatlab.com/blog/types-of-undocumented-matlab-aspects/</link> <comments>http://undocumentedmatlab.com/blog/types-of-undocumented-matlab-aspects/#comments</comments> <pubDate>Thu, 24 Nov 2011 18:00:36 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[High risk of breaking in future versions]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Low risk of breaking in future versions]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Semi-documented feature]]></category> <category><![CDATA[Semi-documented function]]></category> <category><![CDATA[Undocumented feature]]></category> <category><![CDATA[Undocumented function]]></category> <category><![CDATA[Hidden property]]></category> <category><![CDATA[Internal component]]></category> <category><![CDATA[JMI]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[Undocumented property]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=2534</guid> <description><![CDATA[This article lists the different types of undocumented/unsupported/hidden aspects in Matlab<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/reasons-for-undocumented-matlab-aspects/' rel='bookmark' title='Reasons for undocumented Matlab aspects'>Reasons for undocumented Matlab aspects</a> <small>There are many reasons for the numerous undocumented aspects in Matlab - this article explains them....</small></li><li><a
href='http://undocumentedmatlab.com/blog/undocumented-cursorbar-object/' rel='bookmark' title='Undocumented cursorbar object'>Undocumented cursorbar object</a> <small>Matlab's internal undocumented graphics.cursorbar object can be used to present dynamic data-tip cross-hairs...</small></li><li><a
href='http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/' rel='bookmark' title='uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager'>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events/' rel='bookmark' title='Matlab callbacks for Java events'>Matlab callbacks for Java events</a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Why are there so many undocumented aspects in Matlab?</p><p>This is a great question, recently <a
target="_blank" href="http://undocumentedmatlab.com/blog/guide-customization/#comment-61578">asked</a> by a reader of this blog, so I wanted to expand on it in next week&#8217;s article. Before specifying the different reasons, let&#8217;s map the nature of undocumented aspects that we find in Matlab.</p><p>The term <i>undocumented/unsupported</i> (as opposed to <i>mis-documentated</i> or <i>deprecated</i>) actually refers to quite a large number of different types.<br
/> In the following list, the hyperlinks on the list-item titles lead to a list of corresponding articles on this website:</p><ul><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/undocumented-function/">Undocumented functions</a></b><br
/> Matlab functions which appears nowhere in the documentation, are usually built-in functions (do not have an m-file) and can only be inferred from online CSSM posts or usage within one of the Matlab m-functions installed with Matlab (the latter being the usual case). None of these functions is officially supported by MathWorks. <a
target="_blank" href="http://undocumentedmatlab.com/blog/category/mex/">MEX</a> is an important source for such functions.</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/semi-documented-function/">Semi-documented functions</a></b><br
/> Matlab functionality which exists in Matlab m-functions installed with Matlab, but have their main comment separated from the H1 comment line, thereby hiding it from normal view (via Matlab&#8217;s <i><b>help</b></i> function). The H1 comment line itself is simply a standard warning that this function is not officially supported and may change in some future version. To see the actual help comment, simply edit the function (using Matlab&#8217;s <i><b>edit</b></i> function or any text editor) and place a comment sign (%) at the empty line between the H1 comment and the actual help section. The entire help section will then onward be visible via the <i><b>help</b></i> function:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">        <span style="color: #0000FF;">function</span> <span style="color: #080;">&#91;</span>tree, container<span style="color: #080;">&#93;</span> = uitree<span style="color: #080;">&#40;</span><span style="color: #0000FF;">varargin</span><span style="color: #080;">&#41;</span>
        <span style="color: #228B22;">% WARNING: This feature is not supported in MATLAB</span>
        <span style="color: #228B22;">% and the API and functionality may change in a future release.</span>
<span style="color: #0000FF;">fix</span> =&gt;  <span style="color: #228B22;">%</span>
        <span style="color: #228B22;">% UITREE creates a uitree component with hierarchical data in a figure window.</span>
        <span style="color: #228B22;">%   UITREE creates an empty uitree object with default property values in</span>
        <span style="color: #228B22;">%   a figure window.</span>
        <span style="color: #228B22;">%...</span></pre></div></div><p>These functions are not documented in the full documentation (via Matlab&#8217;s <i><b>doc</b></i> function, or online). The odd thing is that some of these functions may appear in the category help output (for example, <i><b>help</b>(&#8216;uitools&#8217;)</i>), and in some cases may even have a fully-visible help section (e.g., <i><b>help</b>(&#8216;setptr&#8217;)</i>), but do not have any online help documentation (<i><b>docsearch</b>(&#8216;setptr&#8217;)</i> fails, and <i><b>doc</b>(&#8216;setptr&#8217;)</i> simply displays the readable help text).</p><p>All these functions are officially unsupported by MathWorks, even when having a readable help section. The rule of thumb appears to be that a Matlab function is supported only if it has online documentation. Note, however, that in some rare cases a documentation discrepancy may be due to a MathWorks documentation error, not to unsupportability&#8230;</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/undocumented-function/">Helper functions</a></b><br
/> Many fully-supported Matlab functions use helper functions that have a specific use in the main (documented) function(s).  Often, these helper functions are tightly-coupled to their documented parents and are useless as stand-alone functions. But quite a few of them have quite useful stand-alone use, as I&#8217;ve already shown in some past articles.</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/undocumented-feature/">Undocumented features</a> and <a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/undocumented-property/">properties</a></b><br
/> Features of otherwise-documented Matlab functions, which appear nowhere in the official documentation. You guessed it – these are also not supported by MathWorks&#8230; Like undocumented functions, you can only infer such features by the occasional CSSM post or a reference somewhere in Matlab&#8217;s m-code.</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/semi-documented-feature/">Semi-documented features</a></b><br
/> Features of otherwise-documented Matlab functions, which are documented in a separate section beneath the main help section, and nowhere else (not in the full doc not the online documentation). If you did not know in advance that these features existed, you could only learn of them by manually looking at Matlab&#8217;s m-files (which is what I do in most cases&#8230;).</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/undocumented-property/">Undocumented properties</a></b><br
/> Many Matlab objects have internal properties, which can be retrieved (via Matlab&#8217;s <i><b>get</b></i> function) and/or set (via the <i><b>set</b></i> function) programmatically. All these properties are fully documented. Many objects also possess hidden properties, some of which are very interesting and useful, but which are undocumented and (oh yes) unsupported. Like undocumented features, they can only be inferred from CSSM or existing code. In a recent <a
target="_blank" href="http://undocumentedmatlab.com/blog/getundoc-get-undocumented-object-properties/">article</a> I described my <i><b>getundoc</b></i> utility, which lists these undocumented properties of specified objects.</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/internal-component/">Internal Matlab classes</a></b><br
/> Matlab uses a vast array of specialized Java classes to handle everything from algorithms to GUI. These classes are (of course) undocumented/unsupported. They can often be accessed directly from the Matlab Command Window or user m-files. GUI classes can be inferred by inspecting the figure frame&#8217;s Java components, and non-GUI classes can often be inferred from references in Matlab&#8217;s m-files.</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/blog/tag/JMI">Matlab-Java integration</a></b><br
/> Matlab&#8217;s GUI interface, as well as the Java-to-Matlab interface (JMI) is fully undocumented and unsupported. In addition to JMI, there are other mechanisms to run Matlab code from within Java (namely JMI, COM and DDE) &#8211; these are all unsupported and by-and-large undocumented.</p></li><li><b><a
target="_blank" href="http://undocumentedmatlab.com/?s=UDD">Matlab&#8217;s UDD mechanism</a></b><br
/> UDD (Unified Data Definition?) is used extensively in Matlab as the internal object-oriented mechanism for describing object properties and functionalities. We can use UDD for a wide variety of uses. UDD was described in a series of articles here in early 2011.</li></ul><p>Next week I will list the reasons that cause MathWorks to decide whether a particular feature or property should be documented or not.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/reasons-for-undocumented-matlab-aspects/' rel='bookmark' title='Reasons for undocumented Matlab aspects'>Reasons for undocumented Matlab aspects</a> <small>There are many reasons for the numerous undocumented aspects in Matlab - this article explains them....</small></li><li><a
href='http://undocumentedmatlab.com/blog/undocumented-cursorbar-object/' rel='bookmark' title='Undocumented cursorbar object'>Undocumented cursorbar object</a> <small>Matlab's internal undocumented graphics.cursorbar object can be used to present dynamic data-tip cross-hairs...</small></li><li><a
href='http://undocumentedmatlab.com/blog/uiundo-matlab-undocumented-undo-redo-manager/' rel='bookmark' title='uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager'>uiundo &#8211; Matlab&#8217;s undocumented undo/redo manager</a> <small>The built-in uiundo function provides easy yet undocumented access to Matlab's powerful undo/redo functionality. This article explains its usage....</small></li><li><a
href='http://undocumentedmatlab.com/blog/matlab-callbacks-for-java-events/' rel='bookmark' title='Matlab callbacks for Java events'>Matlab callbacks for Java events</a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/types-of-undocumented-matlab-aspects/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Undocumented XML functionality</title><link>http://undocumentedmatlab.com/blog/undocumented-xml-functionality/</link> <comments>http://undocumentedmatlab.com/blog/undocumented-xml-functionality/#comments</comments> <pubDate>Thu, 19 Nov 2009 01:12:06 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[Java]]></category> <category><![CDATA[Low risk of breaking in future versions]]></category> <category><![CDATA[Semi-documented feature]]></category> <category><![CDATA[Stock Matlab function]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=751</guid> <description><![CDATA[Matlab's built-in XML-processing functions have several undocumented features that can be used by Java-savvy users<pre> </pre>Related posts:<ol><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/more-undocumented-timing-features/' rel='bookmark' title='More undocumented timing features'>More undocumented timing features</a> <small>There are several undocumented ways in Matlab to get CPU and clock data...</small></li><li><a
href='http://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function/' rel='bookmark' title='ismembc &#8211; undocumented helper function'>ismembc &#8211; undocumented helper function</a> <small>Matlab has several undocumented internal helper functions that can be useful on their own in some cases. This post presents the ismembc function....</small></li><li><a
href='http://undocumentedmatlab.com/blog/reasons-for-undocumented-matlab-aspects/' rel='bookmark' title='Reasons for undocumented Matlab aspects'>Reasons for undocumented Matlab aspects</a> <small>There are many reasons for the numerous undocumented aspects in Matlab - this article explains them....</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>Matlab&#8217;s built-in XML-processing functions have several undocumented features that can be used by Java-savvy users. We should note that the entire XML-support functionality in Matlab is java-based. I understand that some Matlab users have a general aversion to Java, some even going as far as to disable it using the -nojvm startup option. But if you disable Java, Matlab&#8217;s XML functions will simply not work. Matlab&#8217;s own <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/xmlread.html">documentation</a> points users to Sun&#8217;s official Java website for explanations of how to use the XML functionality (the link in the Matlab docpage is dead &#8211; the correct link should probably be <a
target="_blank" rel="nofollow" href="https://jaxp-sources.dev.java.net/nonav/docs/api/">https://jaxp-sources.dev.java.net/nonav/docs/api/</a>, but Sun keeps changing its website so this link could also be dead soon&#8230;).</p><p>Using the full Java XML parsing (<a
target="_blank" rel="nofollow" href="https://jaxp.dev.java.net/">JAXP</a>) functionality is admittedly quite intimidating for the uninitiated, but extremely powerful once you understand how all the pieces fit together. Over the years, several interesting utilities were submitted to the Matlab File Exchange that simplify this intimidating post-processing. See for example <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/3074-xml-parsing-tools">XML parsing tools</a>, the extremely popular <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/4278-xml-toolbox">XML Toolbox</a> and <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/12907-xmliotools">xml_io_tools</a>, the recent <a
target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/18253-xml-data-import">XML data import</a> and perhaps a dozen other utilities.</p><p>Each of Matlab&#8217;s main built-in XML-processing functions, <b><i>xmlread</i></b>, <b><i>xmlwrite</i></b> and <b><i>xslt</i></b> has an internal set of undocumented and unsupported functionalities, which builds on their internal Java implementation. As far as I could tell, these unsupported functionalities were supported at least as early as Matlab 7.2 (R2006a), and possibly even on earlier releases. For the benefit of the Java and/or JAXP -speakers out there (it will probably not help any others), I list Matlab&#8217;s internal description of these unsupported functionalities, annotated with API hyperlinks. These description (sans the links) can be seen by simply editing the m file, as in (the R2008a variant is described below):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">edit</span> xmlread</pre></div></div><h3><i>xmlread</i></h3><p></p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> <span style="color: #080;">&#91;</span>parseResult,p<span style="color: #080;">&#93;</span> = xmlread<span style="color: #080;">&#40;</span>fileName,<span style="color: #0000FF;">varargin</span><span style="color: #080;">&#41;</span></pre></div></div><ul><li>FILENAME can also be an <a
target="_blank" rel="nofollow" href="https://jaxp-sources.dev.java.net/nonav/docs/api/org/xml/sax/InputSource.html">InputSource</a>, <a
target="_blank" rel="nofollow" href="http://java.sun.com/javase/6/docs/api/java/io/File.html">File</a>, or <a
target="_blank" rel="nofollow" href="http://java.sun.com/javase/6/docs/api/java/io/InputStream.html">InputStream</a> object</li><li>DOMNODE = XMLREAD(FILENAME,&#8230;,P,&#8230;) where P is a <a
target="_blank" rel="nofollow" href="http://java.sun.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilder.html">DocumentBuilder</a> object</li><li>DOMNODE = XMLREAD(FILENAME,&#8230;,&#8217;-validating&#8217;,&#8230;) will create a validating parser if one was not provided.</li><li>DOMNODE = XMLREAD(FILENAME,&#8230;,ER,&#8230;) where ER is an <a
target="_blank" rel="nofollow" href="https://jaxp-sources.dev.java.net/nonav/docs/api/org/xml/sax/EntityResolver.html">EntityResolver</a> will set the EntityResolver before parsing</li><li>DOMNODE = XMLREAD(FILENAME,&#8230;,EH,&#8230;) where EH is an <a
target="_blank" rel="nofollow" href="https://jaxp-sources.dev.java.net/nonav/docs/api/org/xml/sax/ErrorHandler.html">ErrorHandler</a> will set the ErrorHandler before parsing</li><li>[DOMNODE,P] = XMLREAD(FILENAME,&#8230;) will return a parser suitable for passing back to XMLREAD for future parses.</li></ul><h3><i>xmlwrite</i></h3><p></p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> xmlwrite<span style="color: #080;">&#40;</span>FILENAME,DOMNODE<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">function</span> str = xmlwrite<span style="color: #080;">&#40;</span>DOMNODE<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">function</span> str = xmlwrite<span style="color: #080;">&#40;</span>SOURCE<span style="color: #080;">&#41;</span>;</pre></div></div><ul><li>FILENAME can also be a <a
target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Uniform_Resource_Name">URN</a>, <a
target="_blank" rel="nofollow" href="http://java.sun.com/javase/6/docs/api/java/io/OutputStream.html">java.io.OutputStream</a> or <a
target="_blank" rel="nofollow" href="http://java.sun.com/javase/6/docs/api/java/io/Writer.html">java.io.Writer</a> object</li><li>SOURCE can also be a SAX <a
target="_blank" rel="nofollow" href="https://jaxp-sources.dev.java.net/nonav/docs/api/org/xml/sax/InputSource.html">InputSource</a>, <a
target="_blank" rel="nofollow" href="https://jaxp-sources.dev.java.net/nonav/docs/api/javax/xml/transform/Source.html">JAXP Source</a>, <a
target="_blank" rel="nofollow" href="http://java.sun.com/javase/6/docs/api/java/io/InputStream.html">InputStream</a>, or <a
target="_blank" rel="nofollow" href="http://java.sun.com/javase/6/docs/api/java/io/Reader.html">Reader</a> object</li></ul><h3><i>xslt</i></h3><p></p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> <span style="color: #080;">&#91;</span>xResultURI,xProcessor<span style="color: #080;">&#93;</span> = xslt<span style="color: #080;">&#40;</span>SOURCE,STYLE,DEST,<span style="color: #0000FF;">varargin</span><span style="color: #080;">&#41;</span></pre></div></div><ul><li>SOURCE can also be a <a
target="_blank" rel="nofollow" href="http://xerces.apache.org/xerces2-j/javadocs/xni/org/apache/xerces/xni/parser/XMLInputSource.html">XSLTInputSource</a></li><li>STYLE can also be a StylesheetRoot or XSLTInputSource</li><li>DEST can also be an XSLTResultTarget.  Note that RESULT may be empty in this case since it may not be possible to determine a URL. If STYLE is absent or empty, the function uses the stylesheet named in the xml-stylesheet processing instruction in the SOURCE XML file.  (This does not always work)</li><li>There is also an entirely undocumented feature: passing a &#8216;-tostring&#8217; input argument transforms the inputs into a displayed text segment, rather than into a displayed URI; the transformed text is returned in the xResultURI output argument.</li></ul><p>Note: internal comments within the Matlab code seem to indicate that XSLT is <a
target="_blank" rel="nofollow" href="http://saxon.sourceforge.net/">SAXON</a>-based, so interested users might use SAXON&#8217;s documentation for accessing additional XSLT-related features/capabilities.</p><p><pre> </pre>Related posts:<ol><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/more-undocumented-timing-features/' rel='bookmark' title='More undocumented timing features'>More undocumented timing features</a> <small>There are several undocumented ways in Matlab to get CPU and clock data...</small></li><li><a
href='http://undocumentedmatlab.com/blog/ismembc-undocumented-helper-function/' rel='bookmark' title='ismembc &#8211; undocumented helper function'>ismembc &#8211; undocumented helper function</a> <small>Matlab has several undocumented internal helper functions that can be useful on their own in some cases. This post presents the ismembc function....</small></li><li><a
href='http://undocumentedmatlab.com/blog/reasons-for-undocumented-matlab-aspects/' rel='bookmark' title='Reasons for undocumented Matlab aspects'>Reasons for undocumented Matlab aspects</a> <small>There are many reasons for the numerous undocumented aspects in Matlab - this article explains them....</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/undocumented-xml-functionality/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Legend &#8216;-DynamicLegend&#8217; semi-documented feature</title><link>http://undocumentedmatlab.com/blog/legend-semi-documented-feature/</link> <comments>http://undocumentedmatlab.com/blog/legend-semi-documented-feature/#comments</comments> <pubDate>Thu, 04 Jun 2009 23:00:22 +0000</pubDate> <dc:creator>Yair Altman</dc:creator> <category><![CDATA[GUI]]></category> <category><![CDATA[Listeners]]></category> <category><![CDATA[Medium risk of breaking in future versions]]></category> <category><![CDATA[Semi-documented feature]]></category> <category><![CDATA[Stock Matlab function]]></category> <category><![CDATA[Listener]]></category> <category><![CDATA[Pure Matlab]]></category> <category><![CDATA[scribe]]></category><guid
isPermaLink="false">http://undocumentedmatlab.com/?p=357</guid> <description><![CDATA[The built-in Matlab legend function has a very useful semi-documented feature for automatic dynamic update, which is explained here.<pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/multi-column-grid-legend/' rel='bookmark' title='Multi-column (grid) legend'>Multi-column (grid) legend</a> <small>This article explains how to use undocumented axes listeners for implementing multi-column plot legends...</small></li><li><a
href='http://undocumentedmatlab.com/blog/undocumented-feature-function/' rel='bookmark' title='Undocumented feature() function'>Undocumented feature() function</a> <small>Matlab's undocumented feature function enables access to some internal experimental features...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-performance/' rel='bookmark' title='Plot performance'>Plot performance</a> <small>Undocumented inner plot mechanisms can be used to significantly improved plotting performance...</small></li><li><a
href='http://undocumentedmatlab.com/blog/context-sensitive-help/' rel='bookmark' title='Context-Sensitive Help'>Context-Sensitive Help</a> <small>Matlab has a hidden/unsupported built-in mechanism for easy implementation of context-sensitive help...</small></li></ol><pre> </pre>]]></description> <content:encoded><![CDATA[<p>In one of my projects, I had to build a GUI in which users could interactively add and remove plot lines from an axes. The problem was that the legend needed to be kept in constant sync with the currently-displayed plot lines. This can of course be done programmatically, but a much simpler solution was to use <em><strong>legend</strong></em>&#8216;s semi-documented &#8216;-DynamicLegend&#8217; feature. Here&#8217;s a simple example:</p><blockquote><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">x=<span style="color: #33f;">0</span><span style="color: #F0F;">:</span>.01<span style="color: #F0F;">:</span><span style="color: #33f;">10</span>;
<span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>x, <span style="color: #0000FF;">sin</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>, <span style="color:#A020F0;">'DisplayName'</span>,<span style="color:#A020F0;">'sin'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">legend</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'-DynamicLegend'</span><span style="color: #080;">&#41;</span>;
&nbsp;
<span style="color: #0000FF;">hold</span> <span style="color: #0000FF;">all</span>;   <span style="color: #228B22;">% add new plot lines on top of previous ones</span>
<span style="color: #0000FF;">plot</span><span style="color: #080;">&#40;</span>x, <span style="color: #0000FF;">cos</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>, <span style="color:#A020F0;">'DisplayName'</span>,<span style="color:#A020F0;">'cos'</span><span style="color: #080;">&#41;</span>;</pre></div></div></blockquote><p>We can see how the dynamic legend automatically keeps in sync with its associated axes contents when plot lines are added/removed, even down to the zoom-box lines&#8230; The legend automatically uses the plot lines &#8216;DisplayName&#8217; property where available, or a standard &#8216;line#&#8217; nametag where not available:<br
/><center><br
/><div
class="wp-caption aligncenter" style="width: 310px"><img
alt="Dynamic legend" src="http://undocumentedmatlab.com/images/legend_animated.gif" title="Dynamic legend" width="300" height="308" /><p
class="wp-caption-text">Dynamic legend</p></div></center></p><p>DynamicLegend works by attaching a listener to the axes child addition/deletion callback (actually, it works on the scribe object, which is a large topic for several future posts). It is sometimes necessary to selectively disable the dynamic behavior. For example, in my GUI I needed to plot several event lines which looked alike, and so I only wanted the first line to be added to the legend. To temporarily disable the DynamicLegend listener, do the following:</p><blockquote><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Try to disable this axes's legend plot-addition listener</span>
legendAxListener = <span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>;
<span style="color: #0000FF;">try</span>
   legendListeners = <span style="color: #0000FF;">get</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">gca</span>,<span style="color:#A020F0;">'ScribeLegendListeners'</span><span style="color: #080;">&#41;</span>;
   legendAxListener = legendListeners.<span style="">childadded</span>;
   <span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>legendAxListener,<span style="color:#A020F0;">'Enable'</span>,<span style="color:#A020F0;">'off'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">catch</span>
   <span style="color: #228B22;">% never mind...</span>
<span style="color: #0000FF;">end</span>
&nbsp;
<span style="color: #228B22;">% Update the axes - the legend will not be updated</span>
<span style="color: #F0F;">...</span>
&nbsp;
<span style="color: #228B22;">% Re-enable the dynamic legend listener</span>
<span style="color: #0000FF;">set</span><span style="color: #080;">&#40;</span>legendAxListener,<span style="color:#A020F0;">'Enable'</span>,<span style="color:#A020F0;">'on'</span><span style="color: #080;">&#41;</span>;</pre></div></div></blockquote><p>Unfortunately, this otherwise-useful DynamicLegend feature throws errors when zooming-in on <em><strong>bar</strong></em> or <em><strong>stairs</strong></em> graphs. This can be replicated by:</p><blockquote><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">figure</span>;
<span style="color: #0000FF;">bar</span><span style="color: #080;">&#40;</span><span style="color: #0000FF;">magic</span><span style="color: #080;">&#40;</span><span style="color: #33f;">4</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>;  <span style="color: #228B22;">%or: stairs(magic(3),magic(3));</span>
<span style="color: #0000FF;">legend</span><span style="color: #080;">&#40;</span><span style="color:#A020F0;">'-DynamicLegend'</span><span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">zoom</span> on;
<span style="color: #228B22;">% Now zoom-in using the mouse to get the errors on the Command Window</span></pre></div></div></blockquote><p>The fix: modify %MATLABROOT%\toolbox\matlab\scribe\@scribe\@legend\init.m line #528 as follows:</p><blockquote><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">%old:</span>
str = <span style="color: #080;">&#91;</span>str<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #F0F;">:</span>insertindex-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;<span style="color: #080;">&#123;</span>newstr<span style="color: #080;">&#125;</span>;str<span style="color: #080;">&#40;</span>insertindex<span style="color: #F0F;">:</span><span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>str<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span>;
&nbsp;
<span style="color: #228B22;">%new:</span>
<span style="color: #0000FF;">if</span> <span style="color: #0000FF;">size</span><span style="color: #080;">&#40;</span>str,<span style="color: #33f;">2</span><span style="color: #080;">&#41;</span>&gt;size<span style="color: #080;">&#40;</span>str,<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>
    str=<span style="color: #080;">&#91;</span>str<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #F0F;">:</span>insertindex-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>,<span style="color: #080;">&#123;</span>newstr<span style="color: #080;">&#125;</span>,str<span style="color: #080;">&#40;</span>insertindex<span style="color: #F0F;">:</span><span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>str<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span>;
<span style="color: #0000FF;">else</span>
    str=<span style="color: #080;">&#91;</span>str<span style="color: #080;">&#40;</span><span style="color: #33f;">1</span><span style="color: #F0F;">:</span>insertindex-<span style="color: #33f;">1</span><span style="color: #080;">&#41;</span>;<span style="color: #080;">&#123;</span>newstr<span style="color: #080;">&#125;</span>;str<span style="color: #080;">&#40;</span>insertindex<span style="color: #F0F;">:</span><span style="color: #0000FF;">length</span><span style="color: #080;">&#40;</span>str<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span>;
<span style="color: #0000FF;">end</span></pre></div></div></blockquote><p>The origin of the bug is that <em><strong>bar</strong></em> and <em><strong>stairs</strong></em> generate <em><strong>hggroup</strong></em> plot-children, which saves the legend strings column-wise rather than the expected row-wise. My fix solves this, but I do not presume this solves all possible problems in all scenarios (please report if you find anything else).</p><h3 id="Semi-documented">Semi-documented</h3><p>The DynamicLegend feature is semi-documented. This means that the feature is explained in a comment within the function (which can be seen via the <strong><em>edit</em></strong>(<span
style="color: rgb(160, 32, 240);">&#8216;legend&#8217;</span>) command), that is nonetheless not part of the official help or doc sections. It is an unsupported feature originally intended only for internal Matlab use (which of course doesn&#8217;t mean we can&#8217;t use it). This feature has existed many releases back (Matlab 7.1 for sure, perhaps earlier), so while it may be discontinued in some future Matlab release, it did have a very long life span&#8230; The down side is that it is not supported: I reported the bar/stairs issue back in mid-2007 and so far this has not been addressed (perhaps it will never be). Even my reported workaround in January this year went unanswered (no hard feelings&#8230;).</p><p>DynamicLegend is a good example of a useful semi-documented feature. Some other examples, which I may cover in future posts, include <strong><em>text</em></strong>(&#8230;,<span
style="color: rgb(160, 32, 240);">&#8216;sc&#8217;</span>), <strong><em>drawnow</em></strong>(<span
style="color: rgb(160, 32, 240);">&#8216;discard&#8217;</span>), several options in <strong><em>pan</em></strong> and <strong><em>datacursormode</em></strong> etc. etc.</p><p>There are also entire semi-documented functions: many of the uitools (e.g., <strong><em>uitree</em></strong>, <strong><em>uiundo</em></strong>), as well as <strong><em>hgfeval</em></strong> and others.</p><p>Have you discovered any useful semi-documented feature or function? If so, then please share your finding in the comments section below.</p><p><pre> </pre>Related posts:<ol><li><a
href='http://undocumentedmatlab.com/blog/multi-column-grid-legend/' rel='bookmark' title='Multi-column (grid) legend'>Multi-column (grid) legend</a> <small>This article explains how to use undocumented axes listeners for implementing multi-column plot legends...</small></li><li><a
href='http://undocumentedmatlab.com/blog/undocumented-feature-function/' rel='bookmark' title='Undocumented feature() function'>Undocumented feature() function</a> <small>Matlab's undocumented feature function enables access to some internal experimental features...</small></li><li><a
href='http://undocumentedmatlab.com/blog/plot-performance/' rel='bookmark' title='Plot performance'>Plot performance</a> <small>Undocumented inner plot mechanisms can be used to significantly improved plotting performance...</small></li><li><a
href='http://undocumentedmatlab.com/blog/context-sensitive-help/' rel='bookmark' title='Context-Sensitive Help'>Context-Sensitive Help</a> <small>Matlab has a hidden/unsupported built-in mechanism for easy implementation of context-sensitive help...</small></li></ol></p><pre> </pre>]]></content:encoded> <wfw:commentRss>http://undocumentedmatlab.com/blog/legend-semi-documented-feature/feed/</wfw:commentRss> <slash:comments>7</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-09 05:09:37 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/tag/semi-documented-feature/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      0.895s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1328789377; expires=Fri, 08-Feb-2013 12:09:37 GMT; path=/
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Thu, 09 Feb 2012 12:09:37 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Thu, 09 Feb 2012 13:09:37 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               1b916a434f059a6669b226142dc433db
Content-Encoding:   gzip
-->
