<?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 property &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/undocumented-property/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Thu, 12 Jul 2018 14:11:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>Plot legend customization</title>
		<link>https://undocumentedmatlab.com/articles/plot-legend-customization?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=plot-legend-customization</link>
					<comments>https://undocumentedmatlab.com/articles/plot-legend-customization#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 12 Jul 2018 14:11:40 +0000</pubDate>
				<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7744</guid>

					<description><![CDATA[<p>Matlab plot legends and their internal components can be customized using a variety of undocumented properties that are easily accessible. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/plot-legend-customization">Plot legend customization</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/plot-legend-title" rel="bookmark" title="Plot legend title">Plot legend title </a> <small>Titles to plot legends are easy to achieve in HG1 (R2014a or earlier), but much more difficult in HG2 (R2014b or newer). ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient" rel="bookmark" title="Plot line transparency and color gradient">Plot line transparency and color gradient </a> <small>Static and interpolated (gradient) colors and transparency can be set for plot lines in HG2. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-markers-transparency-and-color-gradient" rel="bookmark" title="Plot markers transparency and color gradient">Plot markers transparency and color gradient </a> <small>Matlab plot-line markers can be customized to have transparency and color gradients. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/multi-column-grid-legend" rel="bookmark" title="Multi-column (grid) legend">Multi-column (grid) legend </a> <small>This article explains how to use undocumented axes listeners for implementing multi-column plot legends...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Three years ago I <a href="/articles/plot-legend-title" target="_blank">explained</a> how we can use a couple of undocumented hidden properties of the legend in order to add a legend title (the legend object had no <b>Title</b> property back then &#8211; this was only added in a later Matlab release, perhaps as a result of my post). Today I will expand on that article by explaining the plot legend&#8217;s internal graphics hierarchy, how we can access each of these components, and then how this information could be used to customize the separate legend components. Note that the discussion today is only relevant for HG2 legends (i.e. R2014b or newer).<br />
Let&#8217;s start with a simple Matlab plot with a legend:</p>
<pre lang="matlab">
hold all;
hLine1 = plot(1:5);
hLine2 = plot(2:6);
hLegend = legend([hLine1,hLine2], 'Location','SouthEast');
hLegend.Title.String = 'MyLegend';
</pre>
<p><center><figure style="width: 210px" class="wp-caption aligncenter"><img decoding="async" src="https://undocumentedmatlab.com/images/legend_2018_1.gif" alt="Standard Matlab legend" title="Standard Matlab legend" width="210" height="145" /><figcaption class="wp-caption-text">Standard Matlab legend</figcaption></figure></center> This legend is composed of the following visible internal components, which can be customized separately:<br />
<center><img decoding="async" src="https://undocumentedmatlab.com/images/legend_2018_2.gif" alt="Matlab legend components" title="Matlab legend components" width="150" height="110" /></center><br />
<span id="more-7744"></span><br />
<!-- center>[caption id="" align="aligncenter" width="150" caption="Matlab legend components"]<img decoding="async" src="https://undocumentedmatlab.com/images/legend_2018_2.gif" alt="Matlab legend components" title="Matlab legend components" width="150" height="110" />[/caption]<img decoding="async" src="https://undocumentedmatlab.com/images/legend_2018_2.gif" alt="Matlab legend components" title="Matlab legend components" width="150" height="110" /></center --><br />
<!-- span class="alignright"><img decoding="async" src="https://undocumentedmatlab.com/images/legend_2018_2.gif" alt="Matlab legend components" title="Matlab legend components" width="150" height="110" /></span --></p>
<table>
<tr>
<th align="left">Id in screenshot</th>
<th align="left">Accessed via</th>
<th align="left">Object type</th>
<th align="left">Description</th>
<th align="left">Important properties</th>
</tr>
<tr>
<td>1</td>
<td><code>hLegend.Title</code></td>
<td><code>Text</code></td>
<td>Title of the legend</td>
<td><b>Visible</b>, <b>String</b>, <b>Color</b>, <b>FontSize</b>, <b>FontWeight</b>.</td>
</tr>
<tr>
<td>2</td>
<td><code>hLegend.TitleSeparator</code></td>
<td><code>LineStrip</code></td>
<td>Separator line between title and legend entries. Only appears when title is set.</td>
<td><b>Visible</b>, <b>LineStyle</b>, <b>LineWidth</b>, <b>ColorData</b> (4&#215;1 uint8)</td>
</tr>
<tr>
<td>3</td>
<td><code>hLegend.BoxEdge</code></td>
<td><code>LineLoop</code></td>
<td>Box (border) line around the entire legend (including title)</td>
<td><b>Visible</b>, <b>LineStyle</b>, <b>LineWidth</b>, <b>ColorData</b> (4&#215;1 uint8)</td</td>
</tr>
<tr>
<td>4</td>
<td><code>hLegend.EntryContainer.NodeChildren(2)</code></td>
<td><code>LegendEntry</code></td>
<td>Entry row in the legend, corresponding to <code>hLine1</code></td>
<td><b>Icon</b>, <b>Label</b>, <b>Object</b> (line object in main axes)</td>
</tr>
<tr>
<td>5</td>
<td><code>hLegend.EntryContainer.NodeChildren(1)</code></td>
<td><code>LegendEntry</code></td>
<td>Entry row in the legend, corresponding to <code>hLine2</code></td>
<td><b>Icon</b>, <b>Label</b>, <b>Object</b> (line object in main axes)</td>
</tr>
<tr>
<td>6</td>
<td><code>hLegend.EntryContainer.NodeChildren(1).Label</code></td>
<td><code>Text</code></td>
<td>Label of legend entry</td>
<td><b>Visible</b>, <b>String</b>, <b>Color</b>, <b>FontSize</b>, <b>FontWeight</b></td>
</tr>
<tr>
<td>7</td>
<td><code>hLegend.EntryContainer.NodeChildren(1).Icon</code></td>
<td><code>LegendIcon</code></td>
<td>Icon/marker of legend entry</td>
<td><b>Visible</b>, <b>Transform.Children.Children</b> (<code>LineStrip</code> object)</td>
</tr>
</table>
<p>A pivotal object of the legend group are the <code>LegendEntry</code> items, one per legend row:</p>
<pre lang="matlab">
>> hLegendEntry = hLegend.EntryContainer.NodeChildren(1);
>> get(hLegendEntry)
              Children: [3×1 Graphics]
                 Color: [0 0 0]
                 Dirty: 0
             FontAngle: 'normal'
              FontName: 'Helvetica'
              FontSize: 8
            FontWeight: 'normal'
      HandleVisibility: 'on'
               HitTest: 'on'
                  Icon: [1×1 LegendIcon]
                 Index: 0
           Interpreter: 'tex'
                 Label: [1×1 Text]
            LayoutInfo: [1×1 matlab.graphics.illustration.legend.ItemLayoutInfo]
                Legend: [1×1 Legend]
              Listener: [1×1 event.listener]
                Object: [1×1 Line]
               Overlay: [1×1 TriangleStrip]
          OverlayAlpha: 0.65
                Parent: [1×1 Group]
           PeerVisible: 'on'
         PickableParts: 'visible'
              Selected: 'off'
    SelectionHighlight: 'on'
               Visible: 'on'
       VisibleListener: [1×1 event.proplistener]
</pre>
<p>Each <code>LegendEntry</code> contains a back-reference to the original graphics object. In my example above, <code>hLegend.EntryContainer.NodeChildren(2).Object == hLine1</code>, and <code>hLegend.EntryContainer.NodeChildren(2).Object == hLine1</code>. Note how the default legend entries order is the reverse of the order of creation of the original graphics objects. Naturally, we can modify this order by creating the legend py passing it an array of handles that is ordered differently (see the documentation of the <i><b>legend</b></i> function).<br />
To get all the original graphic objects together, in a single array, we could use one of two mechanisms (note the different order of the returned objects):</p>
<pre lang="matlab">
% Alternative #1
>> [hLegend.EntryContainer.NodeChildren.Object]'
ans =
  2×1 Line array:
  Line    (data2)
  Line    (data1)
% Alternative #2
>> hLegend.PlotChildren
ans =
  2×1 Line array:
  Line    (data1)
  Line    (data2)
</pre>
<p>For some reason, accessing the displayed graphic line in <code>LegendEntry</code>&#8216;s <b>Icon</b> is not simple. For example, the <code>LineStrip</code> object that corresponds to <code>hLine2</code> can be gotten via:</p>
<pre lang="matlab">
hLegendEntry = hLegend.EntryContainer.NodeChildren(1);
hLegendIconLine = hLegendEntry.Icon.Transform.Children.Children;  % a LineStrip object in our example
</pre>
<p>I assume that this was done to enable non-standard icons for patches and other complex objects (in which case the displayed icon would not necessarily be a <code>LineStrip</code> object). In the case of a line with markers, for example, <code>hLegendIconLine</code> would be an array of 2 objects: a <code>LineStrip</code> object and a separate <code>Marker</code> object. Still, I think that a direct reference in a <code>hLegend.EntryContainer.NodeChildren(1).Icon</code> property would have helped in 99% of all cases, so that we wouldn&#8217;t need to pass through the <code>Transform</code> object.<br />
Anyway, once we have this object reference(s), we can modify its/their properties. In the case of a <code>LineStrip</code> this includes <b>LineStyle</b>, <b>LineWidth</b>, <b>ColorData</b> (4&#215;1 uint8), and <b>VertexData</b> (which controls position/length):</p>
<pre lang="matlab">
>> get(hLegendIconLine(end))  % LineStrip
          AlignVertexCenters: 'on'
             AmbientStrength: 0.3
                ColorBinding: 'object'
                   ColorData: [4×1 uint8]
                   ColorType: 'truecolor'
             DiffuseStrength: 0.6
            HandleVisibility: 'on'
                     HitTest: 'off'
                       Layer: 'middle'
                     LineCap: 'none'
                    LineJoin: 'round'
                   LineStyle: 'solid'
                   LineWidth: 0.5
               NormalBinding: 'none'
                  NormalData: []
                      Parent: [1×1 Group]
               PickableParts: 'visible'
    SpecularColorReflectance: 1
            SpecularExponent: 10
            SpecularStrength: 0.9
                   StripData: []
                     Texture: [0×0 GraphicsPlaceholder]
                  VertexData: [3×2 single]
               VertexIndices: []
                     Visible: 'on'
       WideLineRenderingHint: 'software'
</pre>
<p>and in the presense of markers:</p>
<pre lang="matlab">
>> get(hLegendIconLine(1))  % Marker
    EdgeColorBinding: 'object'
       EdgeColorData: [4×1 uint8]
       EdgeColorType: 'truecolor'
    FaceColorBinding: 'object'
       FaceColorData: []
       FaceColorType: 'truecolor'
    HandleVisibility: 'on'
             HitTest: 'off'
               Layer: 'middle'
           LineWidth: 0.5
              Parent: [1×1 Group]
       PickableParts: 'visible'
                Size: 6
         SizeBinding: 'object'
               Style: 'circle'
          VertexData: [3×1 single]
       VertexIndices: []
             Visible: 'on'
</pre>
<p>An additional undocumented legend property that is of interest is <b>ItemTokenSize</b>. This is a 2-element numeric array specifying the minimal size of the legend entries&#8217; icon and label. By default <code>hLegend.ItemTokenSize == [30,18]</code>, but we can either expand or shrink the icons/labels by setting different values. For example:</p>
<pre lang="matlab">hLegend.ItemTokenSize == [10,1];  % shrink legend icons and labels</pre>
<p>Note that regardless of the amount that we specify, the actual amount that will be used will be such that all legend labels appear.<br />
Fun: try playing with negative values for the icon and the label and see what happens 🙂<br />
Have you come across any other interesting undocumented aspect of Matlab legends? If so, then please share it in a comment below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/plot-legend-customization">Plot legend customization</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/plot-legend-title" rel="bookmark" title="Plot legend title">Plot legend title </a> <small>Titles to plot legends are easy to achieve in HG1 (R2014a or earlier), but much more difficult in HG2 (R2014b or newer). ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient" rel="bookmark" title="Plot line transparency and color gradient">Plot line transparency and color gradient </a> <small>Static and interpolated (gradient) colors and transparency can be set for plot lines in HG2. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-markers-transparency-and-color-gradient" rel="bookmark" title="Plot markers transparency and color gradient">Plot markers transparency and color gradient </a> <small>Matlab plot-line markers can be customized to have transparency and color gradients. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/multi-column-grid-legend" rel="bookmark" title="Multi-column (grid) legend">Multi-column (grid) legend </a> <small>This article explains how to use undocumented axes listeners for implementing multi-column plot legends...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/plot-legend-customization/feed</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>MathWorks-solicited Java survey</title>
		<link>https://undocumentedmatlab.com/articles/mathworks-solicited-java-survey?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mathworks-solicited-java-survey</link>
					<comments>https://undocumentedmatlab.com/articles/mathworks-solicited-java-survey#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 22 Mar 2017 22:05:34 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[uifigure]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6866</guid>

					<description><![CDATA[<p>MathWorks is soliciting user feedbacks about the use of Java components in Matlab programs. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/mathworks-solicited-java-survey">MathWorks-solicited Java survey</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/mathworks-blogs-facelift" rel="bookmark" title="MathWorks blogs facelift">MathWorks blogs facelift </a> <small>MathWorks has just released a new look-&-feel for their blogs section. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/fixing-a-java-focus-problem" rel="bookmark" title="Fixing a Java focus problem">Fixing a Java focus problem </a> <small>Java components added to Matlab GUIs do not participate in the standard focus cycle - this article explains how to fix this problem....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events-in-r2014a" rel="bookmark" title="Matlab callbacks for Java events in R2014a">Matlab callbacks for Java events in R2014a </a> <small>R2014a changed the way in which Java objects expose events as Matlab callbacks. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-and-java" rel="bookmark" title="UDD and Java">UDD and Java </a> <small>UDD provides built-in convenience methods to facilitate the integration of Matlab UDD objects with Java code - this article explains how...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Over the years I&#8217;ve reported numerous uses for integrating Java components and functionality in Matlab. As I&#8217;ve also <a href="/articles/adding-a-search-box-to-figure-toolbar#uifigure" rel="nofollow" target="_blank">recently reported</a>, MathWorks is apparently making a gradual shift away from standalone Java-based figures, toward browser-based web-enabled figures. <a href="/articles/password-and-spinner-controls-in-matlab-gui#warning" target="_blank">As I surmised</a> a few months ago, MathWorks has created dedicated surveys to solicit user feedbacks on the most important (and undocumented) non-compatible aspects of this paradigm change: one regarding users&#8217; use of the <a href="/articles/javacomponent" rel="nofollow" target="_blank"><i><b>javacomponent</b></i> function</a>, the other regarding the use of the figure&#8217;s <a href="/articles/tag/javaframe" target="_blank"><b>JavaFrame</b> property</a>:</p>
<ul>
<li>Survey regarding usage of the <i><b>javacomponent</b></i> function: <a href="http://www.mathworks.com/javacomponent" rel="nofollow" target="_blank">http://www.mathworks.com/javacomponent</a></li>
<li>Survey regarding usage of the <b>JavaFrame</b> property: <a href="http://www.mathworks.com/javaframe" rel="nofollow" target="_blank">http://www.mathworks.com/javaframe</a></li>
</ul>
<p>In MathWorks&#8217; words:</p>
<blockquote><p>
In order to extend your ability to build MATLAB apps, we understand you sometimes need to make use of undocumented Java UI technologies, such as the JavaFrame property. In response to your needs, we are working to develop documented alternatives that address gaps in our app building offerings.<br />
To help inform our work and plans, we would like to understand how you are using the JavaFrame property. Based on your understanding of how it is being used within your app, please take a moment to fill out the following survey. The survey will take approximately 1-2 minutes to finish.
</p></blockquote>
<p>I urge anyone who uses one or both of these features to let MathWorks know how you&#8217;re using them, so that they could incorporate that functionality into the core (documented) Matlab. The surveys are really short and to the point. If you wish to send additional information, please email George.Caia at mathworks.com.<br />
The more feedback responses that MathWorks will get, the better it will be able to prioritize its R&#038;D efforts for the benefit of all users, and the more likely are certain features to get a documented solution at some future release. If you don&#8217;t take the time now to tell MathWorks how you use these features in your code, don&#8217;t complain if and when they break in the future&#8230;</p>
<h3 id="uses">My personal uses of these features</h3>
<ul>
<li><b>Functionality:</b>
<ul>
<li>Figure: maximize/minimize/restore, enable/disable, always-on-top, toolbar controls, menu customizations (icons, tooltips, font, shortcuts, colors)</li>
<li>Table: sorting, filtering, grouping, column auto-sizing, cell-specific behavior (tooltip, context menu, context-sensitive editor, merging cells)</li>
<li>Tree control</li>
<li>Listbox: cell-specific behavior (tooltip, context menu)</li>
<li>Tri-state checkbox</li>
<li>uicontrols in general: various event callbacks (e.g. mouse hover/unhover, focus gained/lost)</li>
<li>Ability to add Java controls e.g. color/font/date/file selector panel or dropdown, spinner, slider, search box, password field</li>
<li>Ability to add 3rd-party components e.g. JFreeCharts, JIDE controls/panels</li>
</ul>
<p></li>
<li><b>Appearance:</b>
<ul>
<li>Figure: undecorated (frameless), other figure frame aspects</li>
<li>Table: column/cell-specific rendering (alignment, icons, font, fg/bg color, string formatting)</li>
<li>Listbox: auto-hide vertical scrollbar as needed, cell-specific renderer (icon, font, alignment, fg/bg color)</li>
<li>Button/checkbox/radio: icons, text alignment, border customization, Look &#038; Feel</li>
<li>Right-aligned checkbox (button to the right of label)</li>
<li>Panel: border customization (rounded/matte/&#8230;)</li>
</ul>
</li>
</ul>
<p>You can find descriptions/explanations of many of these in posts I made on this website over the years.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/mathworks-solicited-java-survey">MathWorks-solicited Java survey</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/mathworks-blogs-facelift" rel="bookmark" title="MathWorks blogs facelift">MathWorks blogs facelift </a> <small>MathWorks has just released a new look-&-feel for their blogs section. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/fixing-a-java-focus-problem" rel="bookmark" title="Fixing a Java focus problem">Fixing a Java focus problem </a> <small>Java components added to Matlab GUIs do not participate in the standard focus cycle - this article explains how to fix this problem....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events-in-r2014a" rel="bookmark" title="Matlab callbacks for Java events in R2014a">Matlab callbacks for Java events in R2014a </a> <small>R2014a changed the way in which Java objects expose events as Matlab callbacks. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-and-java" rel="bookmark" title="UDD and Java">UDD and Java </a> <small>UDD provides built-in convenience methods to facilitate the integration of Matlab UDD objects with Java code - this article explains how...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/mathworks-solicited-java-survey/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Sending email/text messages from Matlab</title>
		<link>https://undocumentedmatlab.com/articles/sending-email-text-messages-from-matlab?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sending-email-text-messages-from-matlab</link>
					<comments>https://undocumentedmatlab.com/articles/sending-email-text-messages-from-matlab#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 07 Dec 2016 21:24:03 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></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[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6765</guid>

					<description><![CDATA[<p>Sending emails and SMS (text) messages from Matlab is easy, once you know a few quirks.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/sending-email-text-messages-from-matlab">Sending email/text messages from Matlab</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/sending-html-emails-from-matlab" rel="bookmark" title="Sending HTML emails from Matlab">Sending HTML emails from Matlab </a> <small>Matlab's sendmail only sends simple text messages by default; a simple hack can cause it to send HTML-formatted messages. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-system-tray-popup-messages" rel="bookmark" title="Setting system tray popup messages">Setting system tray popup messages </a> <small>System-tray icons and messages can be programmatically set and controlled from within Matlab, using new functionality available since R2007b....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/icon-images-in-matlab-uicontrols" rel="bookmark" title="Icon images &amp; text in Matlab uicontrols">Icon images &amp; text in Matlab uicontrols </a> <small>HTML can be used to add image icons to Matlab listbox and popup (drop-down) controls. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/checking-status-of-warning-messages-in-mex" rel="bookmark" title="Checking status of warning messages in MEX">Checking status of warning messages in MEX </a> <small>Undocumented Mex functions can be used to extract the state of Matlab warnings in run-time. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>In this day and age, applications are expected to communicate with users by sending email/text messages to alert them about applicative events (<i>&#8220;IBM stock purchased @$99.99&#8221;</i> or <i>&#8220;House is on fire!&#8221;</i>). Matlab has included the <a href="http://www.mathworks.com/help/matlab/ref/sendmail.html" rel="nofollow" target="_blank"><i><b>sendmail</b></i> function</a> to handle this for many years. Unfortunately, <i><b>sendmail</b></i> requires some tweaking to be useful on all but the most basic/insecure mail servers. Today&#8217;s post will hopefully fill the missing gaps.<br />
None of the information I&#8217;ll present today is really new &#8211; it was all there already if you just knew what to search for online. But hopefully today&#8217;s post will concentrate all these loose ends in a single place, so it may have some value:</p>
<ul>
<li><a href="#TLS">Using a secure mail server</a></li>
<li><a href="#multiple">Emailing multiple recipients</a></li>
<li><a href="#SMS">Sending text messages</a></li>
<li><a href="#panel">User configuration panel</a></li>
</ul>
<p><span id="more-6765"></span></p>
<h3 id="TLS">Using a secure mail server</h3>
<p>All modern mail servers use end-to-end TLS/SSL encryption. The <i><b>sendmail</b></i> function needs extra configuration to handle such connections, since it is configured for a non-encrypted connection by default. Here&#8217;s the code that does this for gmail, using SMTP server <code>smtp.gmail.com</code> and default port #465 (for other SMTP servers, <a href="https://www.arclab.com/en/kb/email/list-of-smtp-and-pop3-servers-mailserver-list.html" rel="nofollow" target="_blank">see here</a>):</p>
<pre lang="matlab">
setpref('Internet', 'E_mail', from_address);  % sender "from" address, typically same as username, e.g. 'xyz@gmail.com'
setpref('Internet', 'SMTP_Username', username);
setpref('Internet', 'SMTP_Password', password);
setpref('Internet', 'SMTP_Server',   'smtp.gmail.com');
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth',                'true');  % Note: 'true' as a string, not a logical value!
props.setProperty('mail.smtp.starttls.enable',     'true');  % Note: 'true' as a string, not a logical value!
props.setProperty('mail.smtp.socketFactory.port',  '465');   % Note: '465'  as a string, not a numeric value!
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
sendmail(recipient, title, body, attachments);  % e.g., sendmail('recipient@gmail.com', 'Hello world', 'What a nice day!', 'C:\images\sun.jpg')
</pre>
<p>All this is not enough to enable Matlab to connect to gmail&#8217;s SMTP servers. In addition, we need to set the Google account to allow access from &#8220;less secure apps&#8221; (<a href="https://support.google.com/accounts/answer/6010255" rel="nofollow" target="_blank">details</a>, <a href="https://www.google.com/settings/security/lesssecureapps?rfn=27&#038;rfnc=1&#038;asae=2&#038;anexp=lbe-R1_C" rel="nofollow" target="_blank">direct link</a>). Without this, Google will not allow Matlab to relay emails. Other mail servers may require similar server-side account configurations to enable Matlab&#8217;s access.<br />
Note: This code snippet uses a bit of Java as you can see. Under the hood, all networking code in Matlab relies on Java, and <i><b>sendmail</b></i> is no exception. For some reason that I don&#8217;t fully understand, MathWorks chose to label the feature of using <i><b>sendmail</b></i> with secure mail servers as a feature that relies on &#8220;undocumented commands&#8221; and is therefore not listed in <i><b>sendmail</b></i>&#8216;s documentation. Considering the fact that all modern mail servers are secure, this seems to make <i><b>sendmail</b></i> rather useless without the undocumented extension. I assume that TMW are well aware of this, which is the reason they posted a partial documentation in the form of an <a href="https://www.mathworks.com/matlabcentral/answers/93383-how-do-i-use-sendmail-to-send-email-from-matlab-7-2-r2006a-via-the-gmail-server-or-yahoo-server" rel="nofollow" target="_blank">official tech-support answer</a>. I hope that one day MathWorks will incorporate it into <i><b>sendmail</b></i> as optional input args, so that using <i><b>sendmail</b></i> with secure servers would become fully documented and officially supported.</p>
<h3 id="multiple">Emailing multiple recipients</h3>
<p>To specify multiple email recipients, it is not enough to set <i><b>sendmail</b></i>&#8216;s <code>recipient</code> input arg to a string with , or ; delimiters. Instead, we need to provide a cell array of individual recipient strings. For example:</p>
<pre lang="matlab">sendmail({'recipient1@gmail.com','recipient2@gmail.com'}, 'Hello world', 'What a nice day!')</pre>
<p>Note: this feature is actually fully documented in <i><b>sendmail</b></i>&#8216;s doc-page, but for some reason I see that some users are not aware of it (to which it might be said: <i>RTFM!</i>).</p>
<h3 id="SMS">Sending phone text (SMS) messages</h3>
<p>With modern smartphones, text (SMS) messages have become rather outdated, as most users get push notifications of incoming emails. Still, for some users text messages may still be a useful. To send such messages, all we need is to determine our mobile carrier&#8217;s email gateway for SMS messages, and send a simple text message to that email address. For example, to send a text message to T-Mobile number 123-456-7890 in the US, simply email the message to 1234567890@tmomail.net (<a href="https://en.wikipedia.org/wiki/SMS_gateway#Email_clients" rel="nofollow" target="_blank">details</a>).<br />
Ke Feng posted a nice <a href="http://www.mathworks.com/matlabcentral/fileexchange/16649-send-text-message-to-cell-phone" rel="nofollow" target="_blank">Matlab File Exchange utility</a> that wraps this messaging for a wide variety of US carriers.</p>
<h3 id="panel">User configuration panel</h3>
<p>Many GUI programs contain configuration panels/tabs/windows. Enabling the user to set up their own email provider is a typical use-case for such a configuration. Naturally, you&#8217;d want your config panel not to display plain-text password, nor non-integer port numbers. You&#8217;d also want the user to be able to test the email connection.<br />
Here&#8217;s a sample implementation for such a panel that I implemented for a recent project &#8211; I plan to discuss the implementation details of the password and port (spinner) controls in my next post, so stay tuned:<br />
<center><a href="/images/email_config_panel.png" target="_blank"><img decoding="async" alt="User configuration of emails in Matlab GUI (click to zoom-in)" src="https://undocumentedmatlab.com/images/email_config_panel.png" title="User configuration of emails in Matlab GUI (click to zoom-in)" width="75%" style="max-width:842px;"></a><br />
User configuration of emails in Matlab GUI (click to zoom-in)</center></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/sending-email-text-messages-from-matlab">Sending email/text messages from Matlab</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/sending-html-emails-from-matlab" rel="bookmark" title="Sending HTML emails from Matlab">Sending HTML emails from Matlab </a> <small>Matlab's sendmail only sends simple text messages by default; a simple hack can cause it to send HTML-formatted messages. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-system-tray-popup-messages" rel="bookmark" title="Setting system tray popup messages">Setting system tray popup messages </a> <small>System-tray icons and messages can be programmatically set and controlled from within Matlab, using new functionality available since R2007b....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/icon-images-in-matlab-uicontrols" rel="bookmark" title="Icon images &amp; text in Matlab uicontrols">Icon images &amp; text in Matlab uicontrols </a> <small>HTML can be used to add image icons to Matlab listbox and popup (drop-down) controls. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/checking-status-of-warning-messages-in-mex" rel="bookmark" title="Checking status of warning messages in MEX">Checking status of warning messages in MEX </a> <small>Undocumented Mex functions can be used to extract the state of Matlab warnings in run-time. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/sending-email-text-messages-from-matlab/feed</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Faster findjobj</title>
		<link>https://undocumentedmatlab.com/articles/faster-findjobj?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=faster-findjobj</link>
					<comments>https://undocumentedmatlab.com/articles/faster-findjobj#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Mon, 11 Apr 2016 09:18:14 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[FindJObj]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6376</guid>

					<description><![CDATA[<p>the ubiquitous findjobj utility has been significantly improved for speed for the most common use case. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/faster-findjobj">Faster findjobj</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object" rel="bookmark" title="FindJObj &#8211; find a Matlab component&#039;s underlying Java object">FindJObj &#8211; find a Matlab component&#039;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="https://undocumentedmatlab.com/articles/findjobj-gui-display-container-hierarchy" rel="bookmark" title="FindJObj GUI &#8211; display container hierarchy">FindJObj GUI &#8211; display container hierarchy </a> <small>The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/faster-csvwrite-dlmwrite" rel="bookmark" title="Faster csvwrite/dlmwrite">Faster csvwrite/dlmwrite </a> <small>The speed of the builtin csvwrite, dlmwrite functions can be improved dramatically. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/additional-uicontrol-tooltip-hacks" rel="bookmark" title="Additional uicontrol tooltip hacks">Additional uicontrol tooltip hacks </a> <small>Matlab's uicontrol tooltips have several limitations that can be overcome using the control's underlying Java object....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>My <a href="/articles/findjobj-find-underlying-java-object" target="_blank"><i><b>findjobj</b></i> utility</a>, created in 2007 and updated over the years, has received wide recognition and is employed by numerous Matlab programs, including a few dozen utilities in the Matlab File Exchange. I am quite proud of this utility and find it extremely useful for customizing Matlab controls in many ways that are impossible using standard Matlab properties. I have shown <a href="/?s=findjobj" target="_blank">many examples of this</a> in this blog over the past years.<br />
I am happy to announce that I have just uploaded a new version of <i><b>findjobj</b></i> to the <a href="http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects" rel="nofollow" target="_blank">Matlab File Exchange</a>, which significantly improves the utility&#8217;s performance for the most common use-case of a single input and a single output, namely finding the handle of the underlying Java component (peer) of a certain Matlab control:</p>
<pre lang="matlab">
>> hButton = uicontrol('String','click me!');
>> tic, jButton = findjobj(hButton); toc  % old findjobj
Elapsed time is 1.513217 seconds.
>> tic, jButton = findjobj(hButton); toc  % new findjobj
Elapsed time is 0.029348 seconds.
</pre>
<p>The new <i><b>findjobj</b></i> is backward-compatible with the old <i><b>findjobj</b></i> and with all prior Matlab releases. It is a drop-in replacement that will significantly improve your program&#8217;s speed.<br />
The new version relies on several techniques:<span id="more-6376"></span><br />
First, as I <a href="/articles/customizing-matlab-uipanels" rel="nofollow" target="_blank">showed last year</a>, in HG2 (R2014 onward), Matlab <i><b>uipanel</b></i>s have finally become full-featured Java <code>JPanel</code>s, that can be accessed and customized in many interesting manners. More to the point here, we can now directly access the underlying <code>JPanel</code> component handle using the <i><b>uipanel</b></i>&#8216;s hidden <b>JavaFrame</b> property (thanks to MathWorks for supplying this useful hook!). The new <i><b>findjobj</b></i> version detects this and immediately returns this handle if the user specified a <i><b>uipanel</b></i> input.<br />
I still do not know of any direct way to retrieve the underlying Java component&#8217;s handle for Matlab <i><b>uicontrol</b></i>s, this has been a major frustration of mine for quite a few years. So, we need to find the containing Java container in which we will recursively search for the control&#8217;s underlying Java handle. In the old version of <i><b>finjobj</b></i>, we retrieve the containing figure&#8217;s <code>JFrame</code> reference and from it the <code>ContentPane</code> handle, and use this handle as the Java container that is recursively searched. This is quite slow when the figure window is heavily-laden with multiple controls. In the new version, we try to use the specified Matlab <i><b>uicontrol</b></i>&#8216;s direct parent, which is very often a <i><b>uipanel</b></i>. In this case, we can directly retrieve the panel&#8217;s <code>JPanel</code> reference as explained above. This results in a must smaller and faster search since we need to recursively search far fewer controls within the container, compared to the figure&#8217;s <code>ContentPane</code>.<br />
In addition, I used a <a href="/articles/findjobj-gui-display-container-hierarchy#comment-332487" target="_blank">suggestion</a> by blog reader Hannes for a faster recursive search that uses the control&#8217;s tooltip rather than its size, position and class. Finally, the search order is reversed to search backward from the last child component, since this is the component that will most often contain the requested control peer.<br />
Feel free to download and use the new <i><b>findjobj</b></i> version. The code for the fast variant can be found in lines #190-205 and #3375-3415.<br />
Enjoy!<br />
p.s. &#8211; as I explained last week, today&#8217;s discussion, and in general anything that has to do with Java peers of GUI controls, only relates to the existing <code>JFrame</code>-based figure windows, not to the new web-based <i><b>uifigure</b></i>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/faster-findjobj">Faster findjobj</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-find-underlying-java-object" rel="bookmark" title="FindJObj &#8211; find a Matlab component&#039;s underlying Java object">FindJObj &#8211; find a Matlab component&#039;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="https://undocumentedmatlab.com/articles/findjobj-gui-display-container-hierarchy" rel="bookmark" title="FindJObj GUI &#8211; display container hierarchy">FindJObj GUI &#8211; display container hierarchy </a> <small>The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/faster-csvwrite-dlmwrite" rel="bookmark" title="Faster csvwrite/dlmwrite">Faster csvwrite/dlmwrite </a> <small>The speed of the builtin csvwrite, dlmwrite functions can be improved dramatically. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/additional-uicontrol-tooltip-hacks" rel="bookmark" title="Additional uicontrol tooltip hacks">Additional uicontrol tooltip hacks </a> <small>Matlab's uicontrol tooltips have several limitations that can be overcome using the control's underlying Java object....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/faster-findjobj/feed</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>Customizing contour plots part 2</title>
		<link>https://undocumentedmatlab.com/articles/customizing-contour-plots-part-2?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-contour-plots-part-2</link>
					<comments>https://undocumentedmatlab.com/articles/customizing-contour-plots-part-2#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 09 Mar 2016 18:00:49 +0000</pubDate>
				<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HG2]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6304</guid>

					<description><![CDATA[<p>The contour lines of 3D Matlab plot can be customized in many different ways. This is the 2nd article on this issue. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part-2">Customizing contour plots part 2</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part2" rel="bookmark" title="Customizing contour plots part 2">Customizing contour plots part 2 </a> <small>Matlab contour labels' color and font can easily be customized. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots" rel="bookmark" title="Customizing contour plots">Customizing contour plots </a> <small>Contour labels, lines and fill patches can easily be customized in Matlab HG2. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-histogram-plots" rel="bookmark" title="Customizing histogram plots">Customizing histogram plots </a> <small>Basic bar charts and histogram plots can be customized in important aspects. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-figure-toolbar-background" rel="bookmark" title="Customizing figure toolbar background">Customizing figure toolbar background </a> <small>Setting the figure toolbar's background color can easily be done using just a tiny bit of Java magic powder. This article explains how. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A few months ago <a href="/articles/customizing-contour-plots" target="_blank">I discussed</a> various undocumented manners by which we can customize Matlab contour plots. A short while ago I receive an email from a blog reader (thanks Frank!) alerting me to another interesting way by which we can customize such plots, using the contour handle&#8217;s hidden <b>ContourZLevel</b> property. In today&#8217;s post I will explain how we can use this property and expand the discussion with some visualization interactivity.</p>
<h3 id="ContourZLevel">The ContourZLevel property</h3>
<p>The contour handle&#8217;s <b>ContourZLevel</b> property is a hidden property. This means that, just like all other hidden properties, it is accessible if we just happen to know its name (which is easy using my <a href="/articles/getundoc-get-undocumented-object-properties" rel="nofollow" target="_blank"><i><b>getundoc</b></i> utility</a>). This property sets the Z level at which the contour lines are drawn.<br />
For example, by default the <i><b>meshc</b></i> function sets <b>ContourZLevel</b>&#8216;s value to the bottom of the 3D display (in other words, to the axes&#8217; <b>ZLim</b>(1) value). This is done within the <i>mesh.m</i> function:<br />
<center><figure style="width: 350px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" alt="Standard Matlab meshc output (contour at bottom)" src="https://undocumentedmatlab.com/images/meshc1.png" title="Standard Matlab meshc output (contour at bottom)" width="350" height="255" /><figcaption class="wp-caption-text">Standard Matlab meshc output (contour at bottom)</figcaption></figure></center><br />
We can, however, modify the contour&#8217;s level value to any other Z location:<br />
<span id="more-6304"></span></p>
<pre lang="matlab">
% create a mesh and contour plot
handles = meshc(peaks);
% handles is a 2-element array of handles: the surface plot and the contours
hContour = handles(2); % get the handle to the contour lines
hContour.ContourZLevel = 4.5; % set the contour's Z position (default: hAxes.ZLim(1)=-10)
% We can also customize other aspects of the contour lines, for example:
hContour.LineWidth = 2; % set the contour lines' width (default: 0.5)
</pre>
<p><center><figure style="width: 344px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Customized Matlab meshc output" src="https://undocumentedmatlab.com/images/meshc2.png" title="Customized Matlab meshc output" width="344" height="255" /><figcaption class="wp-caption-text">Customized Matlab meshc output</figcaption></figure></center></p>
<h3 id="interactivity">Adding some visualization interactivity</h3>
<p>Now let&#8217;s add some fun interactivity using a vertical slider to control the contour&#8217;s height (Z level). Matlab&#8217;s slider uicontrol is really just an ugly scrollbar, so we&#8217;ll use a Java <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/slider.html" rel="nofollow" target="_blank">JSlider</a> instead:</p>
<pre lang="matlab">
% Add a controlling slider to the figure
jSlider = javaObjectEDT(javax.swing.JSlider);
jSlider.setOrientation(jSlider.VERTICAL);
jSlider.setPaintTicks(true);
jSlider.setMajorTickSpacing(20);
jSlider.setMinorTickSpacing(5);
jSlider.setBackground(java.awt.Color.white);
[hjSlider, hContainer] = javacomponent(jSlider, [10,10,30,120], gcf);
% Set the slider's action callback
hAxes = hContour.Parent;  % handle to containing axes
zmin = hAxes.ZLim(1);
zmax = hAxes.ZLim(2);
zrange = zmax - zmin;
cbFunc = @(hSlider,evtData) set(hContour,'ContourZLevel',hSlider.getValue/100*zrange+zmin);
hjSlider.StateChangedCallback = cbFunc;  % set the callback for slider action events
cbFunc(hjSlider,[]);  % evaluate the callback to synchronize the initial display
</pre>
<p><center><figure style="width: 392px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Interactive contour height" src="https://undocumentedmatlab.com/images/meshc_animated.gif" title="Interactive contour height" width="392" height="256" /><figcaption class="wp-caption-text">Interactive contour height</figcaption></figure></center></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part-2">Customizing contour plots part 2</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part2" rel="bookmark" title="Customizing contour plots part 2">Customizing contour plots part 2 </a> <small>Matlab contour labels' color and font can easily be customized. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots" rel="bookmark" title="Customizing contour plots">Customizing contour plots </a> <small>Contour labels, lines and fill patches can easily be customized in Matlab HG2. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-histogram-plots" rel="bookmark" title="Customizing histogram plots">Customizing histogram plots </a> <small>Basic bar charts and histogram plots can be customized in important aspects. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-figure-toolbar-background" rel="bookmark" title="Customizing figure toolbar background">Customizing figure toolbar background </a> <small>Setting the figure toolbar's background color can easily be done using just a tiny bit of Java magic powder. This article explains how. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/customizing-contour-plots-part-2/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>HG2 update</title>
		<link>https://undocumentedmatlab.com/articles/hg2-update?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hg2-update</link>
					<comments>https://undocumentedmatlab.com/articles/hg2-update#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 16 May 2013 00:38:19 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HG2]]></category>
		<category><![CDATA[JavaFrame]]></category>
		<category><![CDATA[Optical illusion]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3789</guid>

					<description><![CDATA[<p>HG2 appears to be nearing release. It is now a stable mature system. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/hg2-update">HG2 update</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-rulers" rel="bookmark" title="Customizing axes rulers">Customizing axes rulers </a> <small>HG2 axes can be customized in numerous useful ways. This article explains how to customize the rulers. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/customizing-axes-part-5-origin-crossover-and-labels" rel="bookmark" title="Customizing axes part 5 &#8211; origin crossover and labels">Customizing axes part 5 &#8211; origin crossover and labels </a> <small>The axes rulers (axles) can be made to cross-over at any x,y location within the chart. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-part-2" rel="bookmark" title="Customizing axes part 2">Customizing axes part 2 </a> <small>Matlab HG2 axes can be customized in many different ways. This article explains some of the undocumented aspects. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Exactly three years ago, I posted information (<a target="_blank" href="/articles/matlab-hg2/">here</a> and <a target="_blank" href="/articles/new-information-on-hg2/">here</a>) about Matlab&#8217;s upcoming new graphics engine, so-called HG2 (<i>Handle Graphics version 2</i>). At the time, I was sure that HG2 was just around the corner. But three years and six releases have passed, Matlab 7 turned into Matlab 8, and HG1 is still in use. I decided that it was time to revisit the latest state of HG2, as reflected in the latest release, R2013a (Matlab 8.1).<br />
In the past few years, development of HG2 has apparently progressed to a stage where most of the kinks were ironed out. The latest HG2 appears to be quite stable, and in my experience most GUI/graphics utilities run as-is, without any need for tweaking. This is good news, which leads me to think that HG2 will be released soon. It is possible that this could happen as early as the upcoming release (R2013b, 8.2) but I have a gut feeling that it will be in R2014a. I also have a gut feeling that MathWorks will name that release 9.0 rather than 8.3, in keeping with its arch-rival <a target="_blank" rel="nofollow" href="http://www.wolfram.com/mathematica/">Mathematica</a>.<br />
HG2 has improved grid lines, plot anti-aliasing and customizable everything (more on this below). Here&#8217;s a simple plot line as it appears in both HG1 and HG2:</p>
<pre lang='matlab'>
hFig = figure('pos',[100,100,300,250]);
x = -10:0.1:10;
y = 1e7*sin(x)./x;
hLine = plot(x,y);
box off; grid on;
title('HG2 plot');
</pre>
<p><center><figure style="width: 620px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="HG1 plot" src="https://undocumentedmatlab.com/images/HG1_plot.png" title="HG1 plot" width="300" height="325" /><img loading="lazy" decoding="async" alt="HG2 plot" src="https://undocumentedmatlab.com/images/HG2_plot.png" title="HG2 plot" width="300" height="325" /><figcaption class="wp-caption-text">Same plot in HG1 and HG2</figcaption></figure></center><br />
We can see that MathWorks has invested heavily in improving usability. The graphics are now much more visually appealing than before. A lot of thought has gone into small details such as the plot colors and the axes gray shades. The changes are small when taken separately, but the overall gestalt is striking. HG2 will definitely justify my license maintenance cost.<br />
<b><u>Addendum Oct 3 2014</u></b>: HG2 is finally released in Matlab release R2014b (8.4 &#8211; not 9.0 as I surmised above). However, many of the advanced customizations shown in this article are still unsupported and undocumented. I plan to detail them in a separate upcoming series of articles.<br />
<span id="more-3789"></span></p>
<h3 id="customizable">Highly customizable</h3>
<p>Matlab in HG2 mode acts and behaves pretty much as you would expect. There are no visible changes to the Desktop or the graphics interface. The major difference is that all graphics handles, whether interactive controls (figure, uicontrols, uitables, etc.) or graph elements (axes, lines, patches, etc.) are instances of class objects (e.g., <code>matlab.ui.Figure</code> or <code>matlab.graphics.chart.primitive.Line</code>) rather than numeric values. This makes it easy to issue commands such as:</p>
<pre lang='matlab'>
hFig.Color = 'w';
hAxes = gca;
hAxes.Title.Color = 'm';  % default: [0,0,0] = black
hAxes.YRuler.SecondaryLabel.String = 'millions';  % original: 'x10^{6}'
hAxes.YRuler.SecondaryLabel.FontAngle = 'italic';  % default: 'normal'
hAxes.YRuler.Axle.LineStyle = 'dotted';  % default: 'solid'
hAxes.YRuler.Axle.ColorData = uint8([0,100,0,255])';  %=dark green; default: [51 51 51 255], corresponding to [0.2 0.2 0.2 1]
hAxes.YBaseline.Color = 'b';  % default: [0.2 0.2 0.2]
hAxes.YBaseline.Visible = 'on';  % default: 'off'
hAxes.XRuler.Axle.Visible = 'off';  % default: 'on'
hLine.Color = [1,0,0];  %='red'
</pre>
<p>rather than using the corresponding <i><b>set(&#8230;)</b></i> or <i><b>get(&#8230;)</b></i> functions, which are still supported for backward compatibility.<br />
<center><figure style="width: 316px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Customized HG2 plot" src="https://undocumentedmatlab.com/images/HG2_plot2.png" title="Customized HG2 plot" width="316" height="342" /><figcaption class="wp-caption-text">Customized HG2 plot</figcaption></figure></center><br />
Notice how much more customizable HG2 is compared to HG1. I am pretty excited from the huge number of additional possible customizations in HG2 compared to HG1. It is real a pity that many of these customizations rely on hidden/undocumented properties (see below). Hopefully this will change when HG2 is officially released.</p>
<h3 id="observations">Some observations</h3>
<p>Here are a few observations that I collected on the latest HG2, as reflected in R2013a:</p>
<ol>
<li>Java is still supported (hurray!). The warnings about the figure&#8217;s <a target="_blank" href="/articles/disable-entire-figure-window/#JavaFrame"><b>JavaFrame</b> property</a> becoming deprecated have fortunately not been fulfilled (hopefully never). All the Java-based GUI tricks shown on this blog and in my book still work, excluding some minor things here and there which are due to inter-release changes rather than to the new HG2 engine.</li>
<li>In order to access the top-level Java <code>Frame</code> of a figure window, we now need to use <code>javaFrame.fHG2Client</code> rather than <a target="_blank" href="/articles/docking-figures-in-compiled-applications/"><code>javaFrame.fHG1Client</code></a>. The relevant code should now look something like this, in order to be fully-compatible with older Matlab releases:
<pre lang='matlab'>
jFrame = get(handle(hFig), 'JavaFrame');
try
    % This works up to R2011a
    jFrame.fFigureClient.setClientDockable(true);
catch
    try
        % This works from R2008b and up, up to HG2
        jFrame.fHG1Client.setClientDockable(true);
    catch
        % This works in HG2
        jFrame.fHG2Client.setClientDockable(true);
    end
end
</pre>
</li>
<li>Anti-aliasing of plot elements (a.k.a. line -smoothing) is now &#8216;on&#8217; by default (double hurray!). Apparently, MathWorks solved the problems with the existing <a target="_blank" href="/articles/plot-linesmoothing-property/">undocumented <b>LineSmoothing</b> property</a>. Still, for some unknown reason, <b>LineSmoothing</b> remains a hidden/undocumented property. Note that for some objects the property name is different. For example, the axes title (which is a <i><b>text</b></i> object of class <code>matlab.graphics.primitive.Text</code>) has a new property called <b>Smoothing</b> that controls anti-aliasing (unlike <b>LineSmoothing</b>, <b>Smoothing</b> appears to be an un-hidden fully-documented property).<br />
<b><u>R2013b addendum</u></b>: The figure handle now includes a property called <b>GraphicsSmoothing</b> that controls anti-aliasing at the entire figure level (default=&#8217;on&#8217;). No more need to set individual graphic elements, although we still can if we want (alas, this flexibility may be removed soon &#8211; see item #6 below). I would have liked to see the anti-aliasing feature use the same property name for all graphic elements, rather than <b>GraphicsSmoothing/LineSmoothing/Smoothing</b>, but maybe I&#8217;m just being an ungrateful spoil-sport&#8230; The good news about <b>GraphicsSmoothing</b> is that this is a <u>non-hidden</u> property. This means it can be seen with <i><b>get</b>(gcf)</i> and once HG2 becomes live it will become fully documented/supported &#8211; hurray!
</li>
<li>Many new properties have been added to graphic objects, that enable customization of different aspects. For example, we can customize the axes grid-lines, containing box and exponent labels in ways that were impossible in HG1 (triple hurray!). Note that many of these new properties are hidden/undocumented (why the hell for???), so we need a utility such as my <a target="_blank" href="/articles/uiinspect/"><i><b>uiinspect</b></i></a> or <a target="_blank" rel="nofollow" href="/articles/getundoc-get-undocumented-object-properties/"><i><b>getundoc</b></i></a> to detect them. Some of the useful new axes properties include <b>*Ruler, *Baseline, *GridHandle, BoxFrame</b> and <b>BackDrop</b> (I showed an example usage of <b>*Ruler</b> and <b>*Baseline</b> above). I have absolutely no idea why these so-useful properties are kept hidden, it simply makes no sense.</li>
<li>Some existing HG1 properties are missing. For example, the <b>UserData</b> property is no longer available for some Java objects (this is a real pity &#8212; I depended on it for many functionalities, such as storing node-specific data in <i><b>uitree</b></i>/<code>JTree</code> nodes). Similarly, axes no longer have <a target="_blank" href="/articles/plot-liminclude-properties/"><b>*LimInclude</b> properties</a> (this actually makes sense &#8211; these properties are still available in plot lines, where they actually have a use).</li>
<li>Some existing HG1 properties now issue a warning, although they still work. For example:
<pre lang='matlab'>
>> hAxes.DrawMode = 'fast';
Warning: The DrawMode property will be removed in a future release.
(Type "warning off MATLAB:hg:willberemoved" to suppress this warning.)
>> hLine.LineSmoothing
Warning: The LineSmoothing property will be removed in a future release.
(Type "warning off MATLAB:hg:willberemoved" to suppress this warning.)
ans =
on
</pre>
<p><b><u>R2013b addendum</u></b>: <code>hAxes.DrawMode</code> no longer issues a warning, although <code>hLine.LineSmoothing</code> does.
</li>
<li>There is an open bug on R2012b and R2013a whereby the <i><b>clf</b></i> function does not delete <a target="_blank" href="/articles/javacomponent/"><i><b>javacomponent</b></i></a> objects. This bug does not affect HG2, where <i><b>clf</b></i> works properly.</li>
<li>Some GUI components are being placed a pixel or two sideways in HG2 compared to HG1. This has no visual importance except in very rare cases, but it does affect my <a target="_blank" href="/articles/findjobj-find-underlying-java-object/"><i><b>findjobj</b></i> utility</a>, which relies on the component&#8217;s position to find its underlying Java object. I have updated <i><b>findjobj</b></i> for the upcoming HG2 and it should work with both HG1 and HG2.</li>
<li>The default axes and labels color has changed from black to gray ([0.2 0.2 0.2]). Grid lines now use an even lighter gray shade. Visually I think that this is a great change, since it directs the viewer&#8217;s focus on the plot contents rather than the external decorations.
	</li>
<li>The default axes plot color order has changed. The standard plot color is no longer blue (as it was for ages in Matlab), but a bluish tint; the second color is no longer red but light green; the third color is reddish rather than dark green, etc.:
<pre lang='matlab'>
% HG1
>> get(0,'defaultAxesColorOrder')
ans =
            0            0            1
            0          0.5            0
            1            0            0
            0         0.75         0.75
         0.75            0         0.75
         0.75         0.75            0
         0.25         0.25         0.25
%HG2
>> get(0,'defaultAxesColorOrder')
ans =
     0.070588      0.40784      0.70196
      0.92941      0.14118      0.14902
      0.60784       0.7451      0.23922
      0.48235      0.17647       0.4549
            1      0.78039            0
      0.30196       0.7451      0.93333
      0.82353       0.4549            0
</pre>
<p><b><u>R2013b addendum</u></b>: The default colors have changed a bit (for the better I think). I still think that the relative order should more closely match the current order (blue-green-red-etc.), for compatibility with existing apps. A small utility function could be added that modifies the color-order to something that may be better suited for color-differentiation (see Tim Holy&#8217;s excellent <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/29702-generate-maximally-perceptually-distinct-colors">utility</a> for an example).
</li>
<li>HG2 axes no longer forget the previous plot color (unless we used <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/loren/2009/06/03/hold-everything/"><i><b>hold all</b></i></a>) &#8212; in HG2 color cycling is on by default. Note that this causes some visual discrepancies between HG1 and HG2 in plots that use <i><b>hold on</b></i> and have multiple plot lines: In HG1 they were all blue; in HG2 the first is bluish, the second is greenish, then reddish etc.</li>
<li>GUIDE is still the same-ol&#8217; GUIDE (sigh!). The figure toolbar and menubar have likewise not been upgraded, as far as I could tell.</li>
<li>HG2 performance appears to be generally slower than HG1. Hopefully this will improve by the time HG2 is released, since performance has been one of HG1&#8217;s drawbacks all along. In my tests, most GUI/graphic aspects ran only slightly slower in HG2, except for 2D plots that were significantly slower. This is corroborated by running <i><b>bench</b></i>: on my computer, HG1 yields 0.4 for 2D and 0.22 for 3D; in HG2 the performance is 2.1 for 2D and 0.18 for 3D. Looks like the 2D performance still needs some work&#8230;</li>
</ol>
<h3 id="testing">Testing HG2</h3>
<p>As noted in my <a target="_blank" href="/articles/matlab-hg2/">original article</a>, we can start Matlab in HG2 mode by simply adding the startup (command-line) switch <i>-hgVersion 2</i> to the Matlab command (note the space between the <code>-hgVersion</code> and the &#8220;2&#8221;). For example, in Windows, all you need to do is to copy your Matlab shortcut sideways (so that you will always have the standard HG1 version available), then right-click the shortcut, select &#8220;Properties&#8221;, then add <i>-hgVersion 2</i> to the Target field (note the space between &#8220;hgVersion&#8221; and &#8220;2&#8221;). You will probably want to also add the &#8220;HG2&#8221; descriptor to the shortcut name, in the &#8220;General&#8221; tab:<br />
<center><figure style="width: 377px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Matlab startup switch for HG2" src="https://undocumentedmatlab.com/images/HG2_shortcut_props.png" title="Matlab startup switch for HG2" width="377" height="428" /><figcaption class="wp-caption-text">Matlab startup switch for HG2</figcaption></figure></center><br />
If you have any Matlab application that relies on GUI or graphics, I urge you to test it on the new HG2 system. It&#8217;s trivially simple and your application should work exactly the same, or better. If you do detect some incompatibility, please <a href="/articles/hg2-update/#respond">post a comment</a> or <a href="mailto: altmany @gmail.com?subject=HG2 feedback&amp;body=Hi Yair, &amp;cc=;&amp;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=HG2 feedback&amp;body=Hi Yair, '); return false;">shoot me an email</a>. In due course I expect that MathWorks will open an official channel for this, but in the meantime I&#8217;ll be sure to pass the information to the relevant person.<br />
Do take a moment for testing HG2 &#8211; we can all contribute to ensure that when HG2 does come out it will be perfect. It&#8217;s in our interest.</p>
<h3 id="NYC_visit">NYC visit</h3>
<p>If you happen to be in New York next week, I urge you to attend the MATLAB Computational Conference on Thursday May 23 (free <a target="_blank" rel="nofollow" href="http://www.mathworks.com/company/events/conferences/matlab-computational-finance-conference-nyc/2013/registration.html">registration</a>; my presentation is scheduled for 4:50pm). I would be happy to meet you to discuss how I could bring value to your needs, either financial-oriented or not. We could meet at the conference, or anywhere in New York on Wednesday May 22 or Friday May 24.<br />
<center><a href="/articles/nyc-visit-may-2013/"><img loading="lazy" decoding="async" title="Matlab Computational Finance Conference - 23 May 2013" src="https://undocumentedmatlab.com/images/conference_invite_animated.gif" alt="Matlab Computational Finance Conference - 23 May 2013" width="324" height="86"/></a></center></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/hg2-update">HG2 update</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-rulers" rel="bookmark" title="Customizing axes rulers">Customizing axes rulers </a> <small>HG2 axes can be customized in numerous useful ways. This article explains how to customize the rulers. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/customizing-axes-part-5-origin-crossover-and-labels" rel="bookmark" title="Customizing axes part 5 &#8211; origin crossover and labels">Customizing axes part 5 &#8211; origin crossover and labels </a> <small>The axes rulers (axles) can be made to cross-over at any x,y location within the chart. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-part-2" rel="bookmark" title="Customizing axes part 2">Customizing axes part 2 </a> <small>Matlab HG2 axes can be customized in many different ways. This article explains some of the undocumented aspects. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/hg2-update/feed</wfw:commentRss>
			<slash:comments>134</slash:comments>
		
		
			</item>
		<item>
		<title>Pinning annotations to graphs</title>
		<link>https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pinning-annotations-to-graphs</link>
					<comments>https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 12 Dec 2012 18:00:51 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[getundoc]]></category>
		<category><![CDATA[Optical illusion]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[scribe]]></category>
		<category><![CDATA[UDD]]></category>
		<category><![CDATA[UIInspect]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3398</guid>

					<description><![CDATA[<p>Annotation object can be programmatically set at, and pinned-to, plot axes data points. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs">Pinning annotations to graphs</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/plotly-graphs" rel="bookmark" title="Plotly graphs">Plotly graphs </a> <small>Plotly charts can be created and customized in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jfreechart-graphs-and-gauges" rel="bookmark" title="JFreeChart graphs and gauges">JFreeChart graphs and gauges </a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plotly-graphs-in-ipython-notebook" rel="bookmark" title="Plotly graphs in IPython Notebook">Plotly graphs in IPython Notebook </a> <small>Plotly graphs can be embedded in an IPython Notebook directly from Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/bug-and-workaround-in-timeseries-plot" rel="bookmark" title="Bug and workaround in timeseries plot">Bug and workaround in timeseries plot </a> <small>Matlab's internal hgconvertunits function has a bug that affects timeseries plots. Luckily there is a simple workaround....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Many Matlab users are aware of Matlab&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/creating_plots/how-to-annotate-graphs.html">annotation functionality</a>, which enables us to assign graphic elements such as arrows, lines, ellipses and text labels to Matlab figures. Matlab has a corresponding built-in function, <i><b>annotation</b></i>, that enables creation of annotation objects. Through the handle returned by <i><b>annotation</b></i> we can customize the annotation&#8217;s appearance (for example, line width/style or text font properties).</p>
<h3 id="limitations">Limitations of Matlab annotations</h3>
<p>Unfortunately, <i><b>annotation</b></i> has several major deficiencies, that are in fact related:<br />
<figure style="width: 406px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="A Matlab text-arrow annotation (unpinned)" src="https://undocumentedmatlab.com/images/Annotation_unpinned_animated.gif" title="A Matlab text-arrow annotation (unpinned)" width="406" height="298" /><figcaption class="wp-caption-text">A Matlab text-arrow annotation (unpinned)</figcaption></figure></p>
<ol>
<li><i><b>annotation</b></i> requires us to specify the annotation&#8217;s position in normalized <u>figure</u> units. Often, we are interested in an annotation on a plot axes that does NOT span the entire figure&#8217;s content area. To correctly convert the position from plot axes data coordinates to figure coordinates requires non-trivial calculations.</li>
<li>The created annotation is NOT pinned to the plot axes by default. This means that the annotation retains its relative position in the figure when the plot is zoomed, panned or rotated. This results in unintelligible and misleading annotations. We can indeed pin the annotation to the graph, but this requires delicate manual interaction (click the Edit Plot toolbar icon, then right-click the relevant annotation end-point, then select &#8220;Pin to Axes&#8221; from context menu). Unfortunately, the annotation handle does not provide a documented way to do this programmatically.</li>
<li>Finally, the annotation objects are only displayed on top of plot axes &#8211; they are obscured by any GUI uicontrols that may happen to be present in the figure.</li>
</ol>
<p>All of these limitations originate from the underlying implementation of annotation objects in Matlab. This is based on a transparent hidden axes that spans the entire figure&#8217;s content area, on which the annotations are being drawn (also called the <i>scribe layer</i>). The annotations may appear to be connected to the plot axes, but this is merely a visual illusion. In fact, they are located in a separate axes layer. For this reason, <i><b>annotation</b></i> requires figure position &#8211; in fact, the annotation has no information about the axes beneath it. Since plot axes are always obscured by uicontrols, so too is the annotation layer.<br />
Matlab&#8217;s implementation of annotation is an attempt to replicate Java&#8217;s standard <a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html">glass-pane mechanism</a>. But whereas the Java glass-pane is a true transparent layer, on top of all other window components (<a target="_blank" rel="nofollow" href="http://www.codebeach.com/2008/03/introduction-to-glass-panes-in-swing.html">examples</a>), Matlab&#8217;s implementation only works for axes.<br />
Oh well, it&#8217;s better than nothing, I guess. But still, it would be nice if we could specify the annotation in graph (plot axes) data units, and have it pinned automatically without requiring manual user interaction.<br />
<span id="more-3398"></span></p>
<h3 id="Debugging">Debugging the problem</h3>
<p>The obvious first place to start debugging this issue is to go to the annotation handle&#8217;s context-menu (accessible via the <b>UIContextMenu</b> property), drill down to the &#8220;Pin&#8221; menu item and take a look at its callback. We could then use the <i><b><a target="_blank" href="/articles/hgfeval/">hgfeval</a></b></i> function to execute this callback programmatically. Unfortunately, this does not work well, because the context-menu is empty when the annotation is first created. A context-menu is only assigned to the annotation after the Edit Plot toolbar button and then the annotation object are clicked.<br />
Being too lazy in nature to debug this all the way through, I opted for an easier route: I started the Profiler just prior to clicking the context-menu&#8217;s &#8220;Pin to Axes&#8221;, and stopped it immediately afterwards. This showed me the code path (beneath <i>%matlabroot%/toolbox/matlab/scribe/</i>), and placing breakpoints in key code lines enabled me to debug the process step-by-step. This in turn enabled me to take the essence of the pinning code and implement it in my stand-alone application code.<br />
Believe me when I say that the scribe code is complex (anyone say convoluted?). So I&#8217;ll spare you the gruesome details and skip right to the chase.</p>
<h3 id="solution">The solution</h3>
<h5 id="positioning">Positioning the annotation in axes data units</h5>
<p>The first step is to ensure that the initial annotation position is within the figure bounds. Otherwise, the <i><b>annotation</b></i> function will shout. Note that it is ok to move the annotation outside the figure bounds later on (via panning/zooming) &#8211; it is only the initial annotation creation that must be within the figure bounds (i.e., between 0.0-1.0 in normalized X and Y units):</p>
<pre lang='matlab'>
% Prepare the annotation's X position
% Note: we need 2 X values: one for the annotation's head, another for the tail
x = [xValue, xValue];
xlim = get(hAxes,'XLim');
% Prepare the annotation's Y position
% Note: we need 2 Y values: one for the annotation's head, another for the tail
% Note: we use a static Y position here, spanning the center of the axes.
% ^^^^  We could have used some other Y data value for this
yLim = get(hAxes,'YLim');
y = yLim(1) + 0*sum(yLim) + [0.1,0]*diff(ylim);  % TODO: handle reverse, log Y axes
% Ensure that the annotation fits in the window by enlarging
% the axes limits as required
if xValue < xlim(1) || xValue > xlim(2)
    hold(hAxes,'on');
    plot(hAxes,xValue,y(2),'-w');
    drawnow;
    % YLim may have changed, so recalculate y
    yLim = get(hAxes,'YLim');
    y = yLim(1) + 0*sum(yLim) + [0.1,0]*diff(ylim);  % TODO: handle reverse, log Y-axes
end
</pre>
<p>Next, we convert our plot data units, in order to get the annotation&#8217;s requested position in the expected figure units. For this we use <i>%matlabroot%/toolbox/matlab/scribe/@scribe/@scribepin/topixels.m</i>. This is an internal method of the <code>scribepin</code> UDD class, so in order to use it we need to create a dummy <code>scribepin</code> object. <i>topixels</i> then converts the dummy object&#8217;s position from axes data units to pixel units. We then use the undocumented <i><b><a target="_blank" href="/articles/bug-and-workaround-in-timeseries-plot/">hgconvertunits</a></b></i> function to convert from pixel units into normalized figure units:</p>
<pre lang='matlab'>
% Convert axes data position to figure normalized position
% uses %matlabroot%/toolbox/matlab/scribe/@scribe/@scribepin/topixels.m
scribepin = scribe.scribepin('parent',hAxes,'DataAxes',hAxes,'DataPosition',[x;y;[0,0]]');
figPixelPos = scribepin.topixels;
hFig = ancestor(hAxes,'figure');
figPos = getpixelposition(hFig);
figPixelPos(:,2) = figPos(4) - figPixelPos([2,1],2);
figNormPos = hgconvertunits(hFig,[figPixelPos(1,1:2),diff(figPixelPos)],'pixels','norm',hFig);
annotationX = figNormPos([1,1]);
annotationY = figNormPos([2,2]) + figNormPos(4)*[1,0];
</pre>
<h5 id="pinning">Pinning the annotation to the axes data</h5>
<p>Finally, we use the annotation handle&#8217;s <i>pinAtAffordance()</i> method and set the <b>Pin.DataPosition</b> property to the requested X,Y values (we need to do both of these, otherwise the annotation will jump around when we zoom/pan):<br />
<center><figure style="width: 406px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="A Matlab text-arrow annotation (pinned)" src="https://undocumentedmatlab.com/images/Annotation_pinned_animated.gif" title="A Matlab text-arrow annotation (pinned)" width="406" height="298" /><figcaption class="wp-caption-text">A Matlab text-arrow annotation (pinned)</figcaption></figure></center></p>
<pre lang='matlab'>
% Ensure that the annotation is within the axes bounds, then display it
if any([annotationX,annotationY] < 0) || any([annotationX,annotationY] > 1)
    % Annotation position is outside axes boundaries, so bail out without drawing
    hAnnotation = handle([]);
elseif ~isempty(annotationObj)
    % Create a text-arrow annotation with the requested string at the requested position
    hAnnotation = handle(annotation('textarrow', annotationX, annotationY, ...
                                    'String',annotationStr, 'TextColor','b', 'Tag','annotation'));
    % Example for setting annotation properties
    hAnnotation.TextEdgeColor = [.8,.8,.8];
    % Pin the annotation object to the required axes position
    % Note: some of the following could fail in certain cases - never mind
    try
        hAnnotation.pinAtAffordance(1);
        hAnnotation.pinAtAffordance(2);
        hAnnotation.Pin(1).DataPosition = [xValue, y(1), 0];
        hAnnotation.Pin(2).DataPosition = [xValue, y(2), 0];
    catch
        % never mind - ignore (no error)
    end
end
</pre>
<p>p.s. Notice that all this relies on pure Matlab code (i.e., no mention of the dreaded J-word&#8230;). In fact, practically the entire scribe code is available in m-file format in the base Matlab installation. Masochistic readers may find many hours of pleasure sifting through the scribe code functionality for interesting nuggets such as the one above. If you ever find any interesting items, please drop me an email, or post a comment below.</p>
<h3 id="undocumented">Undocumented annotation properties</h3>
<p>Annotation objects have a <u>huge</u> number of undocumented properties. In fact, they have more undocumented properties than documented ones. You can see this using my <i><b><a target="_blank" href="/articles/uiinspect/">uiinspect</a></b></i> or <i><b><a target="_blank" href="/articles/getundoc-get-undocumented-object-properties/">getundoc</a></b></i> utilities. Here is the list for a simple text-arrow annotation, such as the one that we used above:</p>
<pre lang='matlab'>
>> getundoc(hAnnotation)
ans =
              ALimInclude: 'on'
                   Afsize: 6
          ApplicationData: [1x1 struct]
                 Behavior: [1x1 struct]
              CLimInclude: 'on'
               ColorProps: {5x1 cell}
     EdgeColorDescription: 'Color'
        EdgeColorProperty: 'Color'
                  Editing: 'off'
                EraseMode: 'normal'
     FaceColorDescription: 'Head Color'
        FaceColorProperty: 'HeadColor'
             FigureResize: 0
            HeadBackDepth: 0.35
                HeadColor: [0 0 0]
            HeadColorMode: 'auto'
            HeadEdgeColor: [0 0 0]
            HeadFaceAlpha: 1
            HeadFaceColor: [0 0 0]
               HeadHandle: [1x1 patch]
         HeadHypocycloidN: 3
            HeadLineStyle: '-'
            HeadLineWidth: 0.5
               HeadRosePQ: 2
                 HeadSize: 10
             HelpTopicKey: ''
          IncludeRenderer: 'on'
                 MoveMode: 'mouseover'
                    NormX: [0.2 0.4]
                    NormY: [0.5 0.7]
                      Pin: [0x1 double]
                   PinAff: [1 2]
           PinContextMenu: [2x1 uimenu]
                PinExists: [0 0]
              PixelBounds: [0 0 0 0]
        PropertyListeners: [8x1 handle.listener]
        ScribeContextMenu: [9x1 uimenu]
                 Selected: 'off'
             Serializable: 'on'
                ShapeType: 'textarrow'
                    Srect: [2x1 line]
           StoredPosition: []
                TailColor: [0 0 0]
               TailHandle: [1x1 line]
            TailLineStyle: '-'
            TailLineWidth: 0.5
     TextColorDescription: 'Text Color'
            TextColorMode: 'auto'
        TextColorProperty: 'TextColor'
        TextEdgeColorMode: 'manual'
            TextEraseMode: 'normal'
               TextHandle: [1x1 text]
         UpdateInProgress: 0
    VerticalAlignmentMode: 'auto'
              XLimInclude: 'on'
              YLimInclude: 'on'
              ZLimInclude: 'on'
</pre>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs">Pinning annotations to graphs</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/plotly-graphs" rel="bookmark" title="Plotly graphs">Plotly graphs </a> <small>Plotly charts can be created and customized in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jfreechart-graphs-and-gauges" rel="bookmark" title="JFreeChart graphs and gauges">JFreeChart graphs and gauges </a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plotly-graphs-in-ipython-notebook" rel="bookmark" title="Plotly graphs in IPython Notebook">Plotly graphs in IPython Notebook </a> <small>Plotly graphs can be embedded in an IPython Notebook directly from Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/bug-and-workaround-in-timeseries-plot" rel="bookmark" title="Bug and workaround in timeseries plot">Bug and workaround in timeseries plot </a> <small>Matlab's internal hgconvertunits function has a bug that affects timeseries plots. Luckily there is a simple workaround....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/pinning-annotations-to-graphs/feed</wfw:commentRss>
			<slash:comments>13</slash:comments>
		
		
			</item>
		<item>
		<title>Types of undocumented Matlab aspects</title>
		<link>https://undocumentedmatlab.com/articles/types-of-undocumented-matlab-aspects?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=types-of-undocumented-matlab-aspects</link>
					<comments>https://undocumentedmatlab.com/articles/types-of-undocumented-matlab-aspects#respond</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 24 Nov 2011 18:00:36 +0000</pubDate>
				<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[<p>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/types-of-undocumented-matlab-aspects">Types of undocumented Matlab aspects</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/undocumented-plot-marker-types" rel="bookmark" title="Undocumented plot marker types">Undocumented plot marker types </a> <small>Undocumented plot marker styles can easily be accesses using a hidden plot-line property. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types-2" rel="bookmark" title="Setting class property types &#8211; take 2">Setting class property types &#8211; take 2 </a> <small>R2016a saw the addition of class property types. However, a better alternative has existed for many years. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types" rel="bookmark" title="Setting class property types">Setting class property types </a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Why are there so many undocumented aspects in Matlab?<br />
This is a great question, recently <a target="_blank" href="/articles/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.<br />
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="/articles/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="/articles/category/mex/">MEX</a> is an important source for such functions.
</li>
<li><b><a target="_blank" href="/articles/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>
<pre lang='matlab'>
        function [tree, container] = uitree(varargin)
        % WARNING: This feature is not supported in MATLAB
        % and the API and functionality may change in a future release.
fix =>  %
        % UITREE creates a uitree component with hierarchical data in a figure window.
        %   UITREE creates an empty uitree object with default property values in
        %   a figure window.
        %...
</pre>
<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).<br />
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;
</li>
<li><b><a target="_blank" href="/articles/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.
</li>
<li><b><a target="_blank" href="/articles/tag/undocumented-feature/">Undocumented features</a> and <a target="_blank" href="/articles/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.
</li>
<li><b><a target="_blank" href="/articles/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;).
</li>
<li><b><a target="_blank" href="/articles/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="/articles/getundoc-get-undocumented-object-properties/">article</a> I described my <i><b>getundoc</b></i> utility, which lists these undocumented properties of specified objects.
</li>
<li><b><a target="_blank" href="/articles/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.
</li>
<li><b><a target="_blank" href="/articles/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.
</li>
<li><b><a target="_blank" href="/?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>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/types-of-undocumented-matlab-aspects">Types of undocumented Matlab aspects</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/undocumented-plot-marker-types" rel="bookmark" title="Undocumented plot marker types">Undocumented plot marker types </a> <small>Undocumented plot marker styles can easily be accesses using a hidden plot-line property. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types-2" rel="bookmark" title="Setting class property types &#8211; take 2">Setting class property types &#8211; take 2 </a> <small>R2016a saw the addition of class property types. However, a better alternative has existed for many years. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types" rel="bookmark" title="Setting class property types">Setting class property types </a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/types-of-undocumented-matlab-aspects/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>getundoc &#8211; get undocumented object properties</title>
		<link>https://undocumentedmatlab.com/articles/getundoc-get-undocumented-object-properties?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getundoc-get-undocumented-object-properties</link>
					<comments>https://undocumentedmatlab.com/articles/getundoc-get-undocumented-object-properties#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 21 Sep 2011 19:00:16 +0000</pubDate>
				<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HG2]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[schema.prop]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2437</guid>

					<description><![CDATA[<p>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/getundoc-get-undocumented-object-properties">getundoc &#8211; get undocumented object properties</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties" rel="bookmark" title="Displaying hidden handle properties">Displaying hidden handle properties </a> <small>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/accessing-private-object-properties" rel="bookmark" title="Accessing private object properties">Accessing private object properties </a> <small>Private properties of Matlab class objects can be accessed (read and write) using some undocumented techniques. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-properties" rel="bookmark" title="UDD Properties">UDD Properties </a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Last week, I <a target="_blank" href="/articles/controlling-plot-data-tips/#Properties">presented</a> the list of undocumented properties available in Matlab&#8217;s cursor mode and data-tip objects. Over the past two years, I had posted <a target="_blank" href="/articles/category/hidden-property/">quite a few other articles</a> on this website that used such undocumented properties. So today I will show exactly how such properties can be discovered.<br />
Hidden properties are object properties that for some reason or other MathWorks has decided not to expose to the general public. They can still be used by Matlab users, just like any other regular property. But if you use the built-in <i><b>get</b></i> and <i><b>set</b></i> functions to list the object&#8217;s properties, you will not find the hidden properties listed. You need to know the hidden properties&#8217; exact name in order to use them. Which is where today&#8217;s post can help, by showing you how to list these hidden properties. I <a target="_blank" href="/articles/displaying-hidden-handle-properties/">wrote about this</a> a couple of years ago, and today&#8217;s article will expand on that original post.<br />
Hidden properties are by their very nature undocumented and not officially supported. For this reason, you should take extra care when relying on them in your code. They could change functionality or even be removed without prior notice in any future Matlab release. Still, some of these properties enable very important functionality, as I have often shown on this website.</p>
<h3 id="HideUndocumented">HideUndocumented</h3>
<p>There are two distinct manners by which undocumented properties can be seen in Matlab. The simplest was <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/1183#2277">reported</a> by Hans Olsson all the way back in 1997, in one of the very earliest posts on the CSSM newsgroup (there is no earlier public report, as far as I could tell). Since then, this method was mentioned in about a dozen <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/search_results?dur=all&#038;page=1&#038;query=hideundocumented&#038;search=+Go+&#038;search_string=hideundocumented&#038;search_submit=cssm">other CSSM posts</a>.<br />
By setting the Matlab root (handle 0)&#8217;s <b>HideUndocumented</b> property to &#8216;off&#8217; (default=&#8217;on&#8217;), subsequent calls to the built-in <i><b>get</b></i> and <i><b>set</b></i> functions list the hidden properties in addition to the regular ones. Note that <b>HideUndocumented</b> is itself a hidden property, which is why Hans&#8217; post is so important &#8211; he presented us with the loose end that then enabled us to untangle the hidden properties in any other HG object.<br />
Here is a simple example, showing <b>HideUndocumented</b>&#8216;s effect on the root (handle 0) object handle itself (hidden properties are highlighted):</p>
<pre lang='matlab' highlight='45,52,56,61,68,71,79,85,90-91,93-98'>
% Display only regular properties
>> get(0)
	CallbackObject = []
	CommandWindowSize = [86 51]
	CurrentFigure = []
	Diary = off
	DiaryFile = diary
	Echo = off
	FixedWidthFontName = Courier New
	Format = longG
	FormatSpacing = compact
	Language = he_il
	MonitorPositions = [ (2 by 4) double array]
	More = off
	PointerLocation = [1084 590]
	RecursionLimit = [500]
	ScreenDepth = [32]
	ScreenPixelsPerInch = [96]
	ScreenSize = [1 1 1440 900]
	ShowHiddenHandles = off
	Units = pixels
	BeingDeleted = off
	ButtonDownFcn =
	Children = []
	Clipping = on
	CreateFcn =
	DeleteFcn =
	BusyAction = queue
	HandleVisibility = on
	HitTest = on
	Interruptible = on
	Parent = []
	Selected = off
	SelectionHighlight = on
	Tag =
	Type = root
	UIContextMenu = []
	UserData = []
	Visible = on
% Display ALL properties (including hidden ones, which are highlighted below)
>> set(0,'HideUndocumented','off')
>> get(0)
	BlackAndWhite = off
	CallbackObject = []
	CommandWindowSize = [86 51]
	CurrentFigure = []
	Diary = off
	DiaryFile = diary
	Echo = off
	ErrorMessage = [ (1 by 79) char array]
	FixedWidthFontName = Courier New
	Format = longG
	FormatSpacing = compact
	HideUndocumented = off
	Language = he_il
	MonitorPositions = [ (2 by 4) double array]
	More = off
	PointerLocation = [1022 82]
	PointerWindow = [0]
	RecursionLimit = [500]
	ScreenDepth = [32]
	ScreenPixelsPerInch = [96]
	ScreenSize = [1 1 1440 900]
	ShowHiddenHandles = off
	Units = pixels
	AutomaticFileUpdates = on
	BeingDeleted = off
	PixelBounds = [0 0 0 0]
	ButtonDownFcn =
	Children = []
	Clipping = on
	CreateFcn =
	DeleteFcn =
	BusyAction = queue
	HandleVisibility = on
	HelpTopicKey =
	HitTest = on
	Interruptible = on
	Parent = []
	Selected = off
	SelectionHighlight = on
	Serializable = on
	Tag =
	Type = root
	UIContextMenu = []
	UserData = []
	ApplicationData = [ (1 by 1) struct array]
	Behavior = [ (1 by 1) struct array]
	Visible = on
	XLimInclude = on
	YLimInclude = on
	ZLimInclude = on
	CLimInclude = on
	ALimInclude = on
	IncludeRenderer = on
</pre>
<h3 id="schema">Property definitions</h3>
<p>An entirely different mechanism uses the <i><b>schema.prop</b></i> definitions that were <a target="_blank" href="/articles/udd-properties/">presented here</a> by Donn Scull at the beginning of 2011. The idea is to get the object&#8217;s <i><b>classhandle</b></i> reference, from it to get the list of properties definitions, and for each property look at its <b>Visible</b> meta-property: hidden properties will simply have <b>Visible</b>=&#8217;off&#8217;, whereas regular properties will have &#8216;on&#8217;.<br />
It turns out that there is not always a full correspondence between these two mechanism. I can&#8217;t remember specific examples, and perhaps these were fixed in the latest Matlab releases. It doesn&#8217;t matter, because merging the list of hidden properties reported by these two methods is always safe to do. Which is exactly what my <i><b>getundoc</b></i> utility does:</p>
<h3 id="getundoc">getundoc utility</h3>
<p>The <i><b>getundoc</b></i> utility is based on another utility by the same name, posted by <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/authors/31831">Duane Hanselman</a> to the Matlab File Exchange in 2006 (Duane has elected to remove all his submissions from FEX a year or two ago, but that&#8217;s an entirely separate [and extremely heated] topic for a different discussion). Duane&#8217;s original <i><b>getundoc</b></i> utility relied only on the first (<b>HideUndocumented</b>) mechanism.<br />
I have since expanded this utility to include support for the second mechanism, as well as support for the upcoming HG2 (see below). The updated <i><b>getundoc</b></i> is now <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/32934-getundoc-get-undocumented-object-properties">available for download</a> on the File Exchange. Since it&#8217;s a very short utility, I will digress from my norm and simply present its code, in its present form, here:</p>
<pre lang='matlab'>
function c = getundoc(arg)
%GETUNDOC Get Undocumented Object Properties.
% GETUNDOC('OBJECT') or GETUNDOC(H) returns a structure of
% undocumented properties (names & values) for the object having handle
% H or indentified by the string 'OBJECT'.
%
% For example, GETUNDOC('axes') or GETUNDOC(gca) returns undocumented
% property names and values for the axes object.
% Extension of Duane Hanselman's original utility (which is no longer
% available on the File Exchange):
% D.C. Hanselman, University of Maine, Orono, ME 04469
% MasteringMatlab@yahoo.com
% Mastering MATLAB 7
% 2006-01-06
if nargin~=1
   error('One Input Required.')
end
if ischar(arg) % GETUNDOC('OBJECT')
   switch lower(arg)
   case 'root'                                                       % root
      h=0;
      hf=0;
   case 'figure'                                                   % figure
      h=figure('Visible','off');
      hf=h;
   otherwise                          % some other string name of an object
      hf=figure('Visible','off');
      object=str2func(arg);
      try
         h=object('Parent',hf,'Visible','off');
      catch
         error('Unknown Object Type String Provided.')
      end
   end
elseif ishandle(arg) % GETUNDOC(H)
   h=arg;
   hf=0;
else
   error('Unknown Object Handle Provided.')
end
wstate=warning;
warning off                                      % supress warnings about obsolete properties
try set(0,'HideUndocumented','off'); catch; end  % Fails in HG2
undocfnames=fieldnames(get(h));                  % get props including undocumented
try set(0,'HideUndocumented','on'); catch; end   % Fails in HG2
docfnames=fieldnames(get(h));                    % get props excluding undocumented
% Yair 18/3/2010 - add a few more undocs:
try
    % This works in HG1
    props = get(classhandle(handle(h)),'properties');
    undocfnames = [undocfnames; get(props(strcmp(get(props,'Visible'),'off')),'Name')];
catch
    % Yair 18/9/2011: In HG2, the above fails, so use the following workaround:
    try
        prop = findprop(handle(h),undocfnames{1});
        props = prop.DefiningClass.PropertyList;
        undocfnames = [undocfnames; {props.Name}'];   % {props([props.Hidden]).Name}
    catch
        % ignore...
    end
end
c = setdiff(undocfnames,docfnames);      % extract undocumented
% Get the values in struct format, if relevant
if ~isempty(c)
  s = struct;
  for fieldIdx = 1 : length(c)
      try
          fieldName = c{fieldIdx};
          s.(fieldName) = get(h,fieldName);
      catch
          s.(fieldName) = '???';
      end
  end
  c = s;
end
% Yair end
if hf~=0                     % delete hidden figure holding selected object
   delete(hf)
end
warning(wstate)
</pre>
<p>Usage of this utility is extremely simple:</p>
<pre lang='matlab'>
>> getundoc(0)
ans =
             ALimInclude: 'on'
         ApplicationData: [1x1 struct]
    AutomaticFileUpdates: 'on'
                Behavior: [1x1 struct]
           BlackAndWhite: 'off'
             CLimInclude: 'on'
            ErrorMessage: [1x79 char]
            HelpTopicKey: ''
        HideUndocumented: 'on'
         IncludeRenderer: 'on'
             PixelBounds: [0 0 0 0]
           PointerWindow: 0
            Serializable: 'on'
             XLimInclude: 'on'
             YLimInclude: 'on'
             ZLimInclude: 'on'
>> getundoc(gcf)
ans =
               ALimInclude: 'on'
    ActivePositionProperty: 'position'
           ApplicationData: [1x1 struct]
              BackingStore: 'on'
                  Behavior: [1x1 struct]
               CLimInclude: 'on'
                CurrentKey: ''
           CurrentModifier: {1x0 cell}
                 Dithermap: [64x3 double]
             DithermapMode: 'manual'
              DoubleBuffer: 'on'
            ExportTemplate: []
               FixedColors: [3x3 double]
                   HelpFcn: ''
              HelpTopicKey: ''
              HelpTopicMap: ''
           IncludeRenderer: 'on'
                 JavaFrame: [1x1 com.mathworks.hg.peer.HG1FigurePeer]
               MinColormap: 64
             OuterPosition: [436 374 568 502]
               PixelBounds: [0 0 560 420]
             PrintTemplate: []
              Serializable: 'on'
                    UseHG2: 'off'
                WaitStatus: []
               XLimInclude: 'on'
               YLimInclude: 'on'
               ZLimInclude: 'on'
</pre>
<h3 id="HG2">Fixes for HG2</h3>
<p>Unfortunately, in the new <a target="_blank" href="/articles/matlab-hg2/">HG2</a> (which is still not in production, but we must be prepared, mustn&#8217;t we?), the original mechanism above (<b>HideUndocumented</b>) fails completely (there is no such property in the new <code>matlab.ui.root</code> object), whereas the second mechanism (UDD property defs) needs to be modified: Apparently, <i><b>classhandle</b></i> fails for HG2 object handles. Instead, we use the workaround of using <i><b>findprop</b></i> to get the property definition for any regular property, then get its parent (the requested class definition), and then down again to list all available properties. Note that in HG2, the relevant meta-property is <b>Hidden</b> which holds logical (<b><i>true/false</i></b>) values, as opposed to <b>Visible</b> and &#8216;off&#8217;/&#8217;on&#8217; values for HG1 above.<br />
All of these fixes are now incorporated in the <i><b>getundoc</b></i> code that is listed above.<br />
When comparing the list of hidden properties in the existing HG1 and the new HG2, we see many interesting differences. And yes: the figure&#8217;s <a target="_blank" href="/articles/minimize-maximize-figure-window/#JavaFrame"><b>JavaFrame</b></a> property was indeed removed in HG2. Bummer! (don&#8217;t worry &#8211; there are several workarounds up my sleeve&#8230;)<br />
Do you have any favorite hidden property that you use in your code? If so, please tell us about it in a comment <a href="/articles/getundoc-get-undocumented-object-properties/#respond">below</a>.<br />
p.s. &#8211; For all the numerous good people telling me about <a target="_blank" href="/articles/cprintf-display-formatted-color-text-in-command-window/"><i><b>cprintf</b></i></a> &#8211; Yes: I am aware that the latest R2011b release has broken <i><b>cprintf</b></i>&#8216;s functionality. I plan to release a workaround sometime soon, when I have some spare time. I&#8217;ll keep everybody posted of course. Please be patient. (if you can&#8217;t wait, you can always <a target="_blank" href="/consulting/">hire me</a> to fix it sooner; otherwise I need to give priority to my paying clients&#8230;)</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/getundoc-get-undocumented-object-properties">getundoc &#8211; get undocumented object properties</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties" rel="bookmark" title="Displaying hidden handle properties">Displaying hidden handle properties </a> <small>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/accessing-private-object-properties" rel="bookmark" title="Accessing private object properties">Accessing private object properties </a> <small>Private properties of Matlab class objects can be accessed (read and write) using some undocumented techniques. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-properties" rel="bookmark" title="UDD Properties">UDD Properties </a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/getundoc-get-undocumented-object-properties/feed</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>Controlling plot data-tips</title>
		<link>https://undocumentedmatlab.com/articles/controlling-plot-data-tips?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=controlling-plot-data-tips</link>
					<comments>https://undocumentedmatlab.com/articles/controlling-plot-data-tips#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 14 Sep 2011 20:42:40 +0000</pubDate>
				<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[modemanager]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Undocumented property]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2432</guid>

					<description><![CDATA[<p>Data-tips are an extremely useful plotting tool that can easily be controlled programmatically.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/controlling-plot-data-tips">Controlling plot data-tips</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/draggable-plot-data-tips" rel="bookmark" title="Draggable plot data-tips">Draggable plot data-tips </a> <small>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-plot-brushed-data" rel="bookmark" title="Accessing plot brushed data">Accessing plot brushed data </a> <small>Plot data brushing can be accessed programmatically using very simple pure-Matlab code...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/undocumented-plot-marker-types" rel="bookmark" title="Undocumented plot marker types">Undocumented plot marker types </a> <small>Undocumented plot marker styles can easily be accesses using a hidden plot-line property. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Plot <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/creating_plots/data-cursor-displaying-data-values-interactively.html">data tips</a> are a great visualization aid for Matlab plots. They enable users to interactively click on a plot location and see a tool-tip that contains the clicked location&#8217;s coordinates. The displayed tooltip text is even customizable using documented properties of the <i><b><a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/techdoc/ref/datacursormode.html">datacursormode</a></b></i> object.<br />
<center><figure style="width: 431px" class="wp-caption aligncenter"><img decoding="async" alt="plot data tips" src="https://undocumentedmatlab.com/images/datatips.png" title="plot data tips" width="431" /><figcaption class="wp-caption-text">plot data tips</figcaption></figure></center><br />
A client has recently asked me to automatically display an attached data-tip to the last data point of a plotted time series of values. The idea was to immediately see what the latest value of the data series is.<br />
Unfortunately, the official documentation clearly says that:</p>
<blockquote><p>You place data tips only by clicking data objects on graphs. You cannot place them programmatically (by executing code to position a data cursor).</p></blockquote>
<p>Well, this has never stopped us before, has it?</p>
<h3 id="Creating">Creating new data tips</h3>
<p>Under the hood, data tips use a data-cursor mode, which shares many similarities in behavior and programming code with the other plot modes (zoom, pan, <a target="_blank" href="/articles/accessing-plot-brushed-data/">data-brushing</a>, etc.). At any one time, only a single such mode can be active in any figure window (this is a known limitation of the design). The code itself it actually quite complex and handles numerous edge-cases. Understanding it by simply reading the code (under %matlabroot%\toolbox\matlab\graphics\) is actually pretty difficult. A much easier way to understand the programming flow is to liberally distribute breakpoints (start in <i>datacursormode.m</i>) and interactively activate the functionality, then debug the code step-by-step.<br />
Luckily, it turns out that the code to create a new data-tip is actually quite simple: first get the data-cursor mode object, then create a new data tip using the mode&#8217;s <i>createDatatip()</i> method, update some data-tip properties and finally update the data-tip&#8217;s position:</p>
<pre lang='matlab'>
% First plot the data
hLine = plot(xdata, ydata);
% First get the figure's data-cursor mode, activate it, and set some of its properties
cursorMode = datacursormode(gcf);
set(cursorMode, 'enable','on', 'UpdateFcn',@setDataTipTxt);
% Note: the optional @setDataTipTxt is used to customize the data-tip's content text
% Note: the following code was adapted from %matlabroot%\toolbox\matlab\graphics\datacursormode.m
% Create a new data tip
hTarget = handle(hLine);
hDatatip = cursorMode.createDatatip(hTarget);
% Create a copy of the context menu for the datatip:
set(hDatatip,'UIContextMenu',get(cursorMode,'UIContextMenu'));
set(hDatatip,'HandleVisibility','off');
set(hDatatip,'Host',hTarget);
set(hDatatip,'ViewStyle','datatip');
% Set the data-tip orientation to top-right rather than auto
set(hDatatip,'OrientationMode','manual');
set(hDatatip,'Orientation','top-right');
% Update the datatip marker appearance
set(hDatatip, 'MarkerSize',5, 'MarkerFaceColor','none', ...
              'MarkerEdgeColor','k', 'Marker','o', 'HitTest','off');
% Move the datatip to the right-most data vertex point
position = [xdata(end),ydata(end),1; xdata(end),ydata(end),-1];
update(hDatatip, position);
</pre>
<p>Note: If you don&#8217;t like messing with the code, consider using Tim Farajian&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/19877-makedatatip">MakeDataTip</a> utility, which basically does all this behind the scenes. It is much easier to use as a stand-alone utility, although it does not give you the flexiblility with all the data-tip properties as in the code above.</p>
<h3 id="Updating">Updating an existing data tip</h3>
<p>To modify the appearance of a data-tip, we first need to get access to the <code>hDatatip</code> object that we created earlier, either programmatically, or interactively (or both). Since we can access pre-stored handles only of programmatically-created (not interactively-created) data-tips, we need to use a different method. There are actually two ways to do this:<br />
The basic way is to search the relevant axes for objects that have <b>Tag</b>=&#8217;DataTipMarker&#8217;. For each data-tip, we will get two such handles: one for the marker (<b>Type</b>=&#8217;line&#8217;) and the other for the text box tooltip (<b>Type</b>=&#8217;text&#8217;). We can use these to update (for example) the marker size, color and style; and the text&#8217;s font, border and colors.<br />
A better way is to access the <code>graphics.datatip</code> object itself. This can be done using two hidden properties of the <i><b>datacursormode</b></i> object:</p>
<pre lang='matlab'>
% Get the list of all data-tips in the current figure
>> cursorMode = datacursormode(gcf)
cursorMode =
	graphics.datacursormanager
>> cursorMode.DataCursors
ans =
	graphics.datatip: 2-by-1
>> cursorMode.CurrentDataCursor
ans =
	graphics.datatip
>> cursorMode.CurrentDataCursor.get
            Annotation: [1x1 hg.Annotation]
           DisplayName: ''
           HitTestArea: 'off'
          BeingDeleted: 'off'
         ButtonDownFcn: []
              Children: [2x1 double]
              Clipping: 'on'
             CreateFcn: []
             DeleteFcn: []
            BusyAction: 'queue'
      HandleVisibility: 'off'
               HitTest: 'off'
         Interruptible: 'on'
                Parent: 492.005493164063
    SelectionHighlight: 'on'
                   Tag: ''
                  Type: 'hggroup'
              UserData: []
              Selected: 'off'
             FontAngle: 'normal'
              FontName: 'Helvetica'
              FontSize: 8
             FontUnits: 'points'
            FontWeight: 'normal'
             EdgeColor: [0.8 0.8 0.8]
       BackgroundColor: [1 1 0.933333333333333]
             TextColor: [0 0 0]
                Marker: 'o'
            MarkerSize: 5
       MarkerEdgeColor: 'k'
       MarkerFaceColor: 'none'
       MarkerEraseMode: 'normal'
             Draggable: 'on'
                String: {'Date: 01/09/11'  'Value: 573.24'}
               Visible: 'on'
             StringFcn: []
             UpdateFcn: []
         UIContextMenu: [1x1 uicontextmenu]
                  Host: [1x1 graph2d.lineseries]
           Interpolate: 'off'
</pre>
<p>We can see that the returned <code>graphics.datatip</code> object includes properties of both the text-box and the marker, making it easy to modify. Moreover, we can use its aforementioned <i>update</i> method to move the datatip to a different plot position (see example in the code above). In addition, we can also use the self-explanatory <i>getCursorInfo(), getaxes(), makeCurrent(), movetofront()</i> methods, and a few others.</p>
<h3 id="Properties">Cursor mode and data-tip properties</h3>
<p>The <code>graphics.datacursormanager</code> and the <code>graphics.datatip</code> objects have several public properties that we can use:</p>
<pre lang='matlab'>
>> cursorMode.get
              Enable: 'off'
    SnapToDataVertex: 'on'
        DisplayStyle: 'datatip'
           UpdateFcn: @setDataTipTxt
              Figure: [1x1 figure]
>> cursorMode.CurrentDataCursor.get
            Annotation: [1x1 hg.Annotation]
           DisplayName: ''
           HitTestArea: 'off'
      ... % See the list above
</pre>
<p>Both these objects have plenty of additional hidden properties. You can inspect them using my <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methods-properties-callbacks-of-an-object">uiinspect utility</a>. Here is a brief list for reference (R2011b):<br />
<code>graphics.datacursormanager</code>:</p>
<ul>
<li>CurrentDataCursor</li>
<li>DataCursors</li>
<li>Debug</li>
<li>DefaultExportVarName</li>
<li>DefaultPanelPosition</li>
<li>EnableAxesStacking</li>
<li>EnableZStacking</li>
<li>ExternalListeners</li>
<li>HiddenUpdateFcn</li>
<li>NewDataCursorOnClick</li>
<li>OriginalRenderer</li>
<li>OriginalRendererMode</li>
<li>PanelDatatipHandle</li>
<li>PanelHandle</li>
<li>PanelTextHandle</li>
<li>UIContextMenu</li>
<li>UIState</li>
<li>ZStackMinimum</li>
</ul>
<p><code>graphics.datatip</code>:</p>
<ul>
<li>ALimInclude</li>
<li>ApplicationData</li>
<li>Behavior</li>
<li>CLimInclude</li>
<li>DataCursorHandle</li>
<li>DataManagerHandle</li>
<li>Debug</li>
<li>DoThrowStartDragEvent</li>
<li>EmptyArgUpdateFcn</li>
<li>EnableAxesStacking</li>
<li>EnableZStacking</li>
<li>EraseMode</li>
<li>EventObject</li>
<li>ExternalListenerHandles</li>
<li>HelpTopicKey</li>
<li>HostAxes</li>
<li>HostListenerHandles</li>
<li>IncludeRenderer</li>
<li>Invalid</li>
<li>IsDeserializing</li>
<li>MarkerHandle</li>
<li>MarkerHandleButtonDownFcn</li>
<li>Orientation</li>
<li>OrientationMode</li>
<li>OrientationPropertyListener</li>
<li>OriginalDoubleBufferState</li>
<li>PixelBounds</li>
<li>PointsOffset</li>
<li>Position</li>
<li>SelfListenerHandles</li>
<li>Serializable</li>
<li>TextBoxHandle</li>
<li>TextBoxHandleButtonDownFcn</li>
<li>Version</li>
<li>ViewStyle</li>
<li>XLimInclude</li>
<li>YLimInclude</li>
<li>ZLimInclude</li>
<li>ZStackMinimum</li>
<li>uistate</li>
</ul>
<p>As can be seen, if we really want, we can always use the <b>MarkerHandle</b> or <b>TextBoxHandle</b> directly.</p>
<h3 id="Deleting">Deleting data tips</h3>
<p>To delete a specific data-tip, simply call the cursor mode&#8217;s <i>removeDataCursor()</i> method; to delete all data-tips, call its <i>removeAllDataCursors()</i> method:</p>
<pre lang='matlab'>
% Delete the current data-tip
cursorMode.removeDataCursor(cursorMode.CurrentDataCursor)
% Delete all data-tips
cursorMode.removeAllDataCursors()
</pre>
<p>Have you used plot data-tips in some nifty way? If so, please share your experience in a <a href="/articles/controlling-plot-data-tips/#respond">comment</a> below.<br />
p.s. &#8211; did you notice that Java was not mentioned anywhere above? Mode managers use pure-Matlab functionality.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/controlling-plot-data-tips">Controlling plot data-tips</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/draggable-plot-data-tips" rel="bookmark" title="Draggable plot data-tips">Draggable plot data-tips </a> <small>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-plot-brushed-data" rel="bookmark" title="Accessing plot brushed data">Accessing plot brushed data </a> <small>Plot data brushing can be accessed programmatically using very simple pure-Matlab code...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/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="https://undocumentedmatlab.com/articles/undocumented-plot-marker-types" rel="bookmark" title="Undocumented plot marker types">Undocumented plot marker types </a> <small>Undocumented plot marker styles can easily be accesses using a hidden plot-line property. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/controlling-plot-data-tips/feed</wfw:commentRss>
			<slash:comments>82</slash:comments>
		
		
			</item>
	</channel>
</rss>
