<?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>GUIDE &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/guide/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Fri, 04 Aug 2017 09:37:52 +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>Matlab GUI training seminars &#8211; Zurich, 29-30 August 2017</title>
		<link>https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlab-gui-training-seminars-zurich-29-30-august-2017</link>
					<comments>https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017#respond</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 04 Aug 2017 09:37:52 +0000</pubDate>
				<category><![CDATA[Public presentation]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[Callbacks]]></category>
		<category><![CDATA[Figure]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[GUIDE]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JIDE]]></category>
		<category><![CDATA[training]]></category>
		<category><![CDATA[uicontrol]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6992</guid>

					<description><![CDATA[<p>Advanced Matlab training courses on Matlab User Interfaces (GUI) will be presented in Zurich Switzerland on 29-30 August, 2017</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017">Matlab GUI training seminars &#8211; Zurich, 29-30 August 2017</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/matlab-expo-bern-22-june-2017" rel="bookmark" title="Matlab Expo &#8211; Bern, 22 June 2017">Matlab Expo &#8211; Bern, 22 June 2017 </a> <small>I will be speaking about easy-to-use Matlab tricks at the upcoming Matlab Expo in Bern, Switzerland on June 22, 2017. ...</small></li>
<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/images-in-matlab-uicontrols-and-labels" rel="bookmark" title="Images in Matlab uicontrols &amp; labels">Images in Matlab uicontrols &amp; labels </a> <small>Images can be added to Matlab controls and labels in a variety of manners, documented and undocumented. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/training" rel="bookmark" title="New training courses">New training courses </a> <small>I am now offering a new service of professional Matlab training, at your location. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><span class="alignright"><img fetchpriority="high" decoding="async" alt="Advanced Matlab training, Zurich 29-30 August 2017" src="https://undocumentedmatlab.com/images/20140520_153734a_500x321.jpg" title="Advanced Matlab training, Zurich 29-30 August 2017" width="400" height="257"/></span><br />
Advanced Matlab training courses/seminars will be presented by me (Yair) in Zürich, Switzerland on 29-30 August, 2017:</p>
<ul>
<li>August 29 (full day) &#8211; <b>Interactive Matlab GUI</b></li>
<p> <!-- - US$399 (CHF 390.-) ($100 discount if paid by July 31) --></p>
<li>August 30 (full day) &#8211; <b>Advanced Matlab GUI</b></li>
<p> <!-- - US$399 (CHF 390.-) ($100 discount if paid by July 31) --><br />
	<!-- li>Enroll to both courses (2 full days) for a total price of US$699 (CHF 680.-)</li --> <!-- ($150 extra discount if paid by July 31) -->
</ul>
<p><!-- b>Both seminars are confirmed</b>: they do not depend on a minimal number of participants. But there is a limit on the total number of participants, so the sooner you enroll, the more likely you are to get a seat. --><br />
The seminars are targeted at Matlab users who wish to improve their program&#8217;s usability and professional appearance. Basic familiarity with the Matlab environment and coding/programming is assumed. The courses will present a mix of both documented and undocumented aspects, which is not available anywhere else. The curriculum is listed below.<br />
This is a unique opportunity to enhance your Matlab coding skills and improve your program&#8217;s usability in a couple of days<!-- , at a very affordable cost -->.<br />
If you are interested in either or both of these seminars, please <a href="mailto:%20altmany%20@gmail.com?subject=Matlab%20training%20Zurich&amp;body=Hi%20Yair,%20&amp;cc=;&amp;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=Matlab training Zurich&amp;body=Hi Yair, '); return false;">Email me</a> (altmany at gmail dot com).<br />
I can also schedule a dedicated visit to your location, for onsite Matlab training customized to your organization&#8217;s specific needs. Additional information can be found on my <a target="_blank" href="/training/">Training page</a>.<br />
Around the time of the training, I will be traveling to various locations around Switzerland. <!-- in Geneva (Aug 22-27), Bern (Aug 27-28), Zürich (Aug 28-30), and Basel (Aug 30 - Sep 3) --> If you wish to meet me in person to discuss how I could bring value to your project, then please email me (altmany at gmail):</p>
<ul>
<li>Geneva: Aug 22 &#8211; 27</li>
<li>Bern: Aug 27 &#8211; 28</li>
<li>Zürich: Aug 28 &#8211; 30</li>
<li>Stuttgart: Aug 30 &#8211; 31</li>
<li>Basel: Sep 1 &#8211; 3</li>
</ul>
<p><img decoding="async" src="https://undocumentedmatlab.com/images/email-icon.png" width="32" height="22" alt="" style="vertical-align:middle;border:0"/>&nbsp;<a href="mailto: altmany @gmail.com?subject=Matlab consulting/training&#038;body=Hi Yair, &#038;cc=;&#038;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=Matlab consulting/training&#038;body=Hi Yair, '); return false;">Email me</a><br />
<span id="more-6992"></span></p>
<hr/>
<h3 id="GUI">Interactive Matlab GUI &#8211; 29 August, 2017</h3>
<ol>
<li>Introduction to Matlab Graphical User Interfaces (GUI)
<ul>
<li>Design principles and best practices</li>
<li>Matlab GUI alternatives</li>
<li>Typical evolution of Matlab GUI developers</li>
</ul>
</li>
<li>GUIDE – MATLAB&#8217;s GUI Design Editor
<ul>
<li>Using GUIDE to design a custom GUI</li>
<li>Available built-in MATLAB uicontrols</li>
<li>Customizing uicontrols</li>
<li>Important figure and uicontrol properties</li>
<li>GUIDE utility windows</li>
<li>The GUIDE-generated file-duo</li>
</ul>
</li>
<li>Customizing GUI appearance and behavior
<ul>
<li>Programmatic GUI creation and control</li>
<li>GUIDE vs. m-programming</li>
<li>Attaching callback functionality to GUI components</li>
<li>Sharing data between GUI components</li>
<li>The handles data struct</li>
<li>Using handle visibility</li>
<li>Position, size and units</li>
<li>Formatting GUI using HTML</li>
</ul>
</li>
<li>Uitable
<ul>
<li>Displaying data in a MATLAB GUI uitable</li>
<li>Controlling column data type</li>
<li>Customizing uitable appearance</li>
<li>Reading uitable data</li>
<li>Uitable callbacks</li>
<li>Additional customizations using Java</li>
</ul>
</li>
<li>Matlab&#8217;s new App Designer and web-based GUI
<ul>
<li>App Designer environment, widgets and code</li>
<li>The web-based future of Matlab GUI and assumed roadmap</li>
<li>App Designer vs. GUIDE – pros and cons comparison</li>
</ul>
</li>
<li>Performance and interactivity considerations
<ul>
<li>Speeding up the initial GUI generation</li>
<li>Improving GUI responsiveness</li>
<li>Actual vs. perceived performance</li>
<li>Continuous interface feedback</li>
<li>Avoiding common performance pitfalls</li>
<li>Tradeoff considerations</li>
</ul>
</li>
</ol>
<p><!-- Throughout the day, a sample data-structure container class will be developed and presented in phases, illustrating the points discussed in the presentation, along with suggestions and discussion on design alternatives, programming quality, efficiency, robustness, maintainability, and performance. In other words, the seminar will include not just a formal presentation of the material but also a live annotated development of a real-world Matlab class that illustrates the presented topics. --><br />
At the end of this seminar, you will have learned how to:</p>
<ul>
<li>apply GUI design principles in Matlab</li>
<li>create simple Matlab GUIs</li>
<li>manipulate and customize graphs, images and GUI components</li>
<li>display Matlab data in a variety of GUI manners, including data tables</li>
<li>decide between using GUIDE, App Designer and/or programmatic GUI</li>
<li>understand tradeoffs in design and run-time performance</li>
<li>comprehend performance implications, to improve GUI speed and responsiveness</li>
</ul>
<hr/>
<h3 id="AMG">Advanced Matlab GUI &#8211; 30 August, 2017</h3>
<ol>
<li>Advanced topics in Matlab GUI
<ul>
<li>GUI callback interrupts and re-entrancy</li>
<li>GUI units and resizing</li>
<li>Advanced HTML formatting</li>
<li>Using hidden (undocumented) properties</li>
<li>Listening to action and property-change events</li>
<li>Uitab, uitree, uiundo and other uitools</li>
</ul>
</li>
<li>Customizing the figure window
<ul>
<li>Creating and customizing the figure&#8217;s main menu</li>
<li>Creating and using context menus</li>
<li>Creating and customizing figure toolbars</li>
</ul>
</li>
<li>Using Java with Matlab GUI
<ul>
<li>Matlab and Java Swing</li>
<li>Integrating Java controls in Matlab GUI</li>
<li>Handling Java events as Matlab callbacks</li>
<li>Integrating built-in Matlab controls/widgets</li>
<li>Integrating JIDE&#8217;s advanced features and professional controls</li>
<li>Integrating 3rd-party Java components: charts/graphs/widgets/reports</li>
</ul>
</li>
<li>Advanced Matlab-Java GUI
<ul>
<li>Customizing standard Matlab uicontrols</li>
<li>Figure-level customization (maximize/minimize, disable etc.)</li>
<li>Containers and position – Matlab vs. Java</li>
<li>Compatibility aspects and trade-offs</li>
<li>Safe programming with Java in Matlab</li>
<li>Java&#8217;s EDT and timing considerations</li>
<li>Deployment (compiler) aspects</li>
</ul>
</li>
</ol>
<p>At the end of this seminar, you will have learned how to:</p>
<ul>
<li>customize the figure toolbar and main menu</li>
<li>use HTML to format GUI appearance</li>
<li>integrate Java controls in Matlab GUI</li>
<li>customize your Matlab GUI to a degree that you never knew was possible</li>
<li>create a modern-looking professional GUI in Matlab</li>
</ul>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017">Matlab GUI training seminars &#8211; Zurich, 29-30 August 2017</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/matlab-expo-bern-22-june-2017" rel="bookmark" title="Matlab Expo &#8211; Bern, 22 June 2017">Matlab Expo &#8211; Bern, 22 June 2017 </a> <small>I will be speaking about easy-to-use Matlab tricks at the upcoming Matlab Expo in Bern, Switzerland on June 22, 2017. ...</small></li>
<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/images-in-matlab-uicontrols-and-labels" rel="bookmark" title="Images in Matlab uicontrols &amp; labels">Images in Matlab uicontrols &amp; labels </a> <small>Images can be added to Matlab controls and labels in a variety of manners, documented and undocumented. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/training" rel="bookmark" title="New training courses">New training courses </a> <small>I am now offering a new service of professional Matlab training, at your location. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/matlab-gui-training-seminars-zurich-29-30-august-2017/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>AppDesigner&#039;s mlapp file format</title>
		<link>https://undocumentedmatlab.com/articles/appdesigner-mlapp-file-format?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=appdesigner-mlapp-file-format</link>
					<comments>https://undocumentedmatlab.com/articles/appdesigner-mlapp-file-format#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 17 Aug 2016 17:00:04 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[AppDesigner]]></category>
		<category><![CDATA[GUIDE]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[uifigure]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6613</guid>

					<description><![CDATA[<p>MLAPP files created by AppDesigner can be inspected and manipulated outside AppDesigner. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/appdesigner-mlapp-file-format">AppDesigner&#039;s mlapp file format</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/fig-files-format" rel="bookmark" title="FIG files format">FIG files format </a> <small>FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/mlintfailurefiles" rel="bookmark" title="MLintFailureFiles or: Why can&#039;t I save my m-file?!">MLintFailureFiles or: Why can&#039;t I save my m-file?! </a> <small>Sometimes Matlab gets into a state where it cannot use a valid m-file. This article explains what can be done. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-axes-tick-labels-format" rel="bookmark" title="Setting axes tick labels format">Setting axes tick labels format </a> <small>Matlab plot axes ticks can be customized in a way that will automatically update whenever the tick values change. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance" rel="bookmark" title="File deletion memory leaks, performance">File deletion memory leaks, performance </a> <small>Matlab's delete function leaks memory and is also slower than the equivalent Java function. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Six years ago, I exposed the fact that <a href="/articles/fig-files-format" rel="nofollow" target="_blank">*.fig files are simply MAT files in disguise</a>. This information, in addition to the data format that I explained in that article, can help us to introspect and modify FIG files without having to actually display the figure onscreen.<br />
Matlab has changed significantly since 2010, and one of the exciting new additions is the <a href="/articles/sliders-in-matlab-gui#AppDesigner" rel="nofollow" target="_blank">AppDesigner</a>, Matlab&#8217;s new GUI layout designer/editor. Unfortunately, AppDesigner still has quite a few limitations in functionality and behavior. I expect that this will improve in upcoming releases since AppDesigner is undergoing active development. But in the meantime, it makes sense to see whether we could directly introspect and potentially manipulate AppDesigner&#8217;s output (*.mlapp files), as we could with GUIDE&#8217;s output (*.fig files).<br />
A situation for checking this was recently raised by a reader on the Answers forum: apparently <a href="https://www.mathworks.com/matlabcentral/answers/279042-app-designer-s-editor-is-slow-and-gets-stuck-alot" rel="nofollow" target="_blank">AppDesigner becomes increasingly sluggish</a> when the figure&#8217;s code has more than a few hundred lines of code (i.e., a very simplistic GUI). In today&#8217;s post I intend to show how we can explore the resulting *.mlapp file, and possibly manipulate it in a text editor outside AppDesigner.<br />
<center><figure style="width: 598px" class="wp-caption aligncenter"><img decoding="async" alt="Matlab's new AppDesigner (a somewhat outdated screenshot)" src="https://undocumentedmatlab.com/images/slider_AppDesigner.png" title="Matlab's new AppDesigner (a somewhat outdated screenshot)" width="598" height="376" /><figcaption class="wp-caption-text">Matlab's new AppDesigner (a somewhat outdated screenshot)</figcaption></figure></center><br />
<span id="more-6613"></span></p>
<h3 id="format">The MLAPP file format</h3>
<p>Apparently, *.mlapp files are simply ZIP files in disguise (note: not MAT files as for *.fig files). A typical MLAPP&#8217;s zipped contents contains the following files (note that this might be a bit different on different Matlab releases):</p>
<ul>
<li><i>[Content_Types].xml</i> &#8211; this seems to be application-independent:
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
   <default Extension="mat" ContentType="application/vnd.mathworks.matlab.appDesigner.appModel+mat"/>
   <default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
   <default Extension="xml" ContentType="application/vnd.mathworks.matlab.code.document+xml;plaincode=true"/>
   <override ContentType="application/vnd.openxmlformats-package.core-properties+xml" PartName="/metadata/coreProperties.xml"/>
   <override ContentType="application/vnd.mathworks.package.coreProperties+xml" PartName="/metadata/mwcoreProperties.xml"/>
   <override ContentType="application/vnd.mathworks.package.corePropertiesExtension+xml" PartName="/metadata/mwcorePropertiesExtension.xml"/>
</types>
</pre>
</li>
<li><i>_rels/.rels</i> &#8211; also application-independent:
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
   <relationship Type="http://schemas.mathworks.com/matlab/code/2013/relationships/document" Target="matlab/document.xml" Id="rId1"/>
   <relationship Type="http://schemas.mathworks.com/package/2012/relationships/coreProperties" Target="metadata/mwcoreProperties.xml" Id="rId2"/>
   <relationship Type="http://schemas.mathworks.com/package/2014/relationships/corePropertiesExtension" Target="metadata/mwcorePropertiesExtension.xml" Id="rId3"/>
   <relationship Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="metadata/coreProperties.xml" Id="rId4"/>
   <relationship Type="http://schemas.mathworks.com/appDesigner/app/2014/relationships/appModel" Target="appdesigner/appModel.mat" Id="rId5"/>
</relationships>
</pre>
</li>
<li><i>metadata/coreProperties.xml</i> &#8211; contains the timestamp of figure creation and last update:
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<cp:coreProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties">
   <dcterms:created xsi:type="dcterms:W3CDTF">2016-08-01T18:20:26Z</dcterms:created>
   <dcterms:modified xsi:type="dcterms:W3CDTF">2016-08-01T18:20:27Z</dcterms:modified>
</cp:coreProperties>
</pre>
</li>
<li><i>metadata/mwcoreProperties.xml</i> &#8211; contains information on the generating Matlab release:
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<mwcoreProperties xmlns="http://schemas.mathworks.com/package/2012/coreProperties">
   <contentType>application/vnd.mathworks.matlab.app</contentType>
   <contentTypeFriendlyName>MATLAB App</contentTypeFriendlyName>
   <matlabRelease>R2016a</matlabRelease>
</mwcoreProperties>
</pre>
</li>
<li><i>metadata/mwcorePropertiesExtension.xml</i> &#8211; more information about the generating Matlab release. Note that the version number is not exactly the same as the main Matlab version number: here we have 9.0.0.328027 whereas the main Matlab version number is 9.0.0.341360. I do not know whether this is checked anywhere.
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<mwcoreProperties xmlns="http://schemas.mathworks.com/package/2014/corePropertiesExtension">
   <matlabVersion>9.0.0.328027</matlabVersion>
</mwcoreProperties>
</pre>
</li>
<li><i>appdesigner/appModel.mat</i> &#8211; This is a simple MAT file that holds a single Matlab object called &#8220;appData&#8221; (of type <code>appdesigner.internal.serialization.app.AppData</code>)  the information about the <i><b>uifigure</b></i>, similar in concept to the <i>*.fig</i> files generated by the old GUIDE:
<pre lang="matlab">
>> d = load('C:\Yair\App3\appdesigner\appModel.mat')
Warning: Functionality not supported with figures created with the uifigure function. For more information,
see Graphics Support in App Designer.
(Type "warning off MATLAB:ui:uifigure:UnsupportedAppDesignerFunctionality" to suppress this warning.)
d =
    appData: [1x1 appdesigner.internal.serialization.app.AppData]
>> d.appData
ans =
  AppData with properties:
      UIFigure: [1x1 Figure]
      CodeData: [1x1 appdesigner.internal.codegeneration.model.CodeData]
      Metadata: [1x1 appdesigner.internal.serialization.app.AppMetadata]
    ToolboxVer: '2016a'
>> d.appData.CodeData
ans =
  CodeData with properties:
    GeneratedClassName: 'App3'
             Callbacks: [0x0 appdesigner.internal.codegeneration.model.AppCallback]
            StartupFcn: [1x1 appdesigner.internal.codegeneration.model.AppCallback]
       EditableSection: [1x1 appdesigner.internal.codegeneration.model.CodeSection]
            ToolboxVer: '2016a'
>> d.appData.Metadata
ans =
  AppMetadata with properties:
    GroupHierarchy: {}
        ToolboxVer: '2016a'
</pre>
</li>
<li><i>matlab/document.xml</i> &#8211; this file contains a copy of the figure&#8217;s classdef code in plain-text XML:
<pre lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
   <w:body>
      <w:p>
         <w:pPr>
            <w:pStyle w:val="code"/>
         </w:pPr>
         <w:r>
            <w:t>
               <![CDATA[classdef App2 < matlab.apps.AppBase % Properties that correspond to app components properties (Access = public) UIFigure matlab.ui.Figure UIAxes matlab.ui.control.UIAxes Button matlab.ui.control.Button CheckBox matlab.ui.control.CheckBox ListBoxLabel matlab.ui.control.Label ListBox matlab.ui.control.ListBox end methods (Access = public) function results = func(app) % Yair 1/8/2016 end end % App initialization and construction methods (Access = private) % Create UIFigure and components function createComponents(app) % Create UIFigure app.UIFigure = uifigure; app.UIFigure.Position = [100 100 640 480]; app.UIFigure.Name = 'UI Figure'; setAutoResize(app, app.UIFigure, true) % Create UIAxes app.UIAxes = uiaxes(app.UIFigure); title(app.UIAxes, 'Axes'); xlabel(app.UIAxes, 'X'); ylabel(app.UIAxes, 'Y'); app.UIAxes.Position = [23 273 300 185]; % Create Button app.Button = uibutton(app.UIFigure, 'push'); app.Button.Position = [491 378 100 22]; % Create CheckBox app.CheckBox = uicheckbox(app.UIFigure); app.CheckBox.Position = [491 304 76 15]; % Create ListBoxLabel app.ListBoxLabel = uilabel(app.UIFigure); app.ListBoxLabel.HorizontalAlignment = 'right'; app.ListBoxLabel.Position = [359 260 43 15]; app.ListBoxLabel.Text = 'List Box'; % Create ListBox app.ListBox = uilistbox(app.UIFigure); app.ListBox.Position = [417 203 100 74]; end end methods (Access = public) % Construct app function app = App2() % Create and configure components createComponents(app) % Register the app with App Designer registerApp(app, app.UIFigure) if nargout == 0 clear app end end % Code that executes before app deletion function delete(app) % Delete UIFigure when app is deleted delete(app.UIFigure) end end end]]&gt;
            </w:t>
         </w:r>
      </w:p>
   </w:body>
</w:document>
</pre>
</li>
</ul>
<p>I do not know why the code is duplicated, both in <i>document.xml</i> and (twice!) in <i>appModel.mat</i>. On the face of it, this does not seem to be a wise design decision.</p>
<h3 id="editing">Editing MLAPP files outside AppDesigner</h3>
<p>We can presumably edit the app in an external editor as follow:</p>
<ol>
<li>Open the <i>*.mlapp</i> file in your favorite zip viewer (e.g., winzip or winrar). You may need to rename/copy the file as <i>*.zip</i>.</li>
<li>Edit the contents of the contained <i>matlab/document.xml</i> file in your favorite text editor (Matlab&#8217;s editor for example)</li>
<li>Load <i>appdesigner/appModel.mat</i> into Matlab workspace.</li>
<li>Go to <code>appData.CodeData.EditableSection.Code</code> and update the cell array with the lines of your updated code (one cell element per user-code line).</li>
<li>Do the same with <code>appData.CodeData.GeneratedCode</code> (if existing), which holds the same data as <code>appData.CodeData.EditableSection.Code</code> but also including the AppDesigner-generated [non-editable] code.</li>
<li>Save the modified appData struct back into <i>appdesigner/appModel.mat</i></li>
<li>Update the zip file (<i>*.mlapp</i>) with the updated <i>appModel.mat</i> and <i>document.xml</i></li>
</ol>
<p>In theory, it is enough to extract the classdef code and same it in a simple <i>*.m</i> file, but then you would not be able to continue using AppDesigner to make layout modifications, and you would need to make all the changes manually in the m-file. If you wish to continue using AppDesigner after you modified the code, then you need to save it back into the <i>*.mlapp</i> file as explained above.<br />
If you think this is not worth all the effort, then you&#8217;re probably right. But you must admit that it&#8217;s a bit fun to poke around&#8230;<br />
One day maybe I&#8217;ll create wrapper utilities (<i><b>mlapp2m</b></i> and <i><b>m2mlapp</b></i>) that do all this automatically, in both directions. Or maybe one of my readers here will pick up the glove and do it sooner &#8211; are you up for the challenge?</p>
<h3 id="caveat">Caveat Emptor</h3>
<p>Note that the MLAPP file format is deeply undocumented and subject to change without prior notice in upcoming Matlab releases. In fact, MathWorker Chris Portal <a href="https://www.mathworks.com/matlabcentral/answers/279042#comment_383621" rel="nofollow" target="_blank">warns us</a> that:</p>
<blockquote><p>A word of caution for anyone that tries this undocumented/unsupported poking into their MLAPP file. Taking this approach will almost certainly guarantee your app to not load in one of the subsequent releases. Just something to consider in your off-roading expedition!</p></blockquote>
<p>Then again, the same could have been said about the FIG and other binary file formats used by Matlab, which remained essentially the same for the past decade: Some internal field values may have changed but not the general format, and in any case the newer releases still accept files created with previous releases. For this reason, I speculate that future AppDesigners will accept MLAPP files created by older releases, possibly even hand-modified MLAPP files. Perhaps a CRC hash code of some sort will be expected, but I believe that any MLAPP that we modify today will still work in future releases. However, I could well be mistaken, so please be very careful with this knowledge. I trust that you can make up your own mind about whether it is worth the risk (and fun) or not.<br />
AppDesigner is destined to gradually replace the aging GUIDE over the upcoming years. They currently coexist since AppDesigner (and its web-based uifigures) still does not contain all the functionality that GUIDE (and JFrame-based figures) provides (<a href="/articles/customizing-uifigures-part-1#comment-384672" rel="nofollow" target="_blank">a few examples</a>). I already posted a few short posts about AppDesigner (use the <a href="/articles/tag/appdesigner" rel="nofollow" target="_blank">AppDesigner tag</a> to list them), and today&#8217;s article is another in that series. Over the next few years I intend to publish more on AppDesigner and its associated new GUI framework (<a href="/articles/tag/uifigure" rel="nofollow" target="_blank">uifigures</a>).</p>
<h3 id="Zurich">Zurich visit, 21-31 Aug 2016</h3>
<p>I will be traveling to Zürich for a business trip between August 21-31. If you are in the Zürich area and wish to meet me to discuss how I could bring value to your work, then please email me (altmany at gmail).</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/appdesigner-mlapp-file-format">AppDesigner&#039;s mlapp file format</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/fig-files-format" rel="bookmark" title="FIG files format">FIG files format </a> <small>FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/mlintfailurefiles" rel="bookmark" title="MLintFailureFiles or: Why can&#039;t I save my m-file?!">MLintFailureFiles or: Why can&#039;t I save my m-file?! </a> <small>Sometimes Matlab gets into a state where it cannot use a valid m-file. This article explains what can be done. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-axes-tick-labels-format" rel="bookmark" title="Setting axes tick labels format">Setting axes tick labels format </a> <small>Matlab plot axes ticks can be customized in a way that will automatically update whenever the tick values change. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/file-deletion-memory-leaks-performance" rel="bookmark" title="File deletion memory leaks, performance">File deletion memory leaks, performance </a> <small>Matlab's delete function leaks memory and is also slower than the equivalent Java function. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/appdesigner-mlapp-file-format/feed</wfw:commentRss>
			<slash:comments>13</slash:comments>
		
		
			</item>
		<item>
		<title>Undocumented button highlighting</title>
		<link>https://undocumentedmatlab.com/articles/undocumented-button-highlighting?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=undocumented-button-highlighting</link>
					<comments>https://undocumentedmatlab.com/articles/undocumented-button-highlighting#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 05 Feb 2014 16:00:48 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[GUIDE]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[uicontrol]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4635</guid>

					<description><![CDATA[<p>Matlab button uicontrols can easily be highlighted by simply setting their Value property. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/undocumented-button-highlighting">Undocumented button highlighting</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/borderless-button-used-for-plot-properties" rel="bookmark" title="Borderless button used for plot properties">Borderless button used for plot properties </a> <small>A borderless button can be used to add unobtrusive functionality to plot axes...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/toolbar-button-labels" rel="bookmark" title="Toolbar button labels">Toolbar button labels </a> <small>GUI toolbar button labels can easily be set and customized using underlying Java components. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/button-customization" rel="bookmark" title="Button customization">Button customization </a> <small>Matlab's button uicontrols (pushbutton and togglebutton) are basically wrappers for a Java Swing JButton object. This post describes how the buttons can be customized using this Java object in ways that are impossible using pure Matlab....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/hgs-undocumented-parameters-interface" rel="bookmark" title="HG&#039;s undocumented parameters interface">HG&#039;s undocumented parameters interface </a> <small>Some HG functions also accept inputs parameters in a struct fields rather than the normal P-V pairs format. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>One of my consulting clients approached me yesterday with a mystery: In his GUIDE-generated GUI, one of the buttons had a bluish tint, and no obvious property seemed to control this or to differentiate it from its sibling controls. Here&#8217;s a parred-down version of his GUI:<br />
<center><figure style="width: 225px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Highlighted GUI button" src="https://undocumentedmatlab.com/images/button_highlight1.png" title="Highlighted GUI button" width="225" height="25" /><figcaption class="wp-caption-text">Highlighted GUI button</figcaption></figure></center><br />
So while it was very nice to have a highlighted button in this manner, the fact that he did not know why it happened and how to control it was a bit unsettling. Which is where I came in, and it turns out that the solution to the mystery is simple and very easy to use. My client now happily switches button highlights on and off, just for the fun of it&#8230;<br />
Before I describe the solution (spoiler alert: scroll down), I think it is instructional to understand the unsuccessful attempts, so here goes:<br />
<span id="more-4635"></span></p>
<h3 id="alternatives">Various alternatives</h3>
<p>Our first attempts to understand the situation were to modify the button control&#8217;s obvious suspect properties:</p>
<ul>
<li><b>String</b> &#8211; the button had an <a target="_blank" href="/articles/button-customization/">HTML label</a>. One might presume that this caused the highlighting tint, perhaps an <a target="_blank" href="/articles/images-in-matlab-uicontrols-and-labels/">HTML image</a> painted the background? <a target="_blank" href="/articles/html-support-in-matlab-uicomponents/">HTML labels for uicontrols</a> are really cool so it would be a pity to have to stop using them. Fortunately, replacing the HTML label with a simple string had no effect, so we can keep using HTML labels safely and freely. But we&#8217;re still left with our mystery, so moving on&#8230;</li>
<li><b>Border</b> &#8211; yet another suspect: the <a target="_blank" href="/articles/customizing-uicontrol-border/">control&#8217;s border</a> and <a target="_blank" href="/articles/borderless-button-used-for-plot-properties/">fly-over appearance feature</a> affects its appearance. This also proved a dead-end: all the buttons had simple default borders, nothing special about the highlighted one.</li>
<li><b>Background</b> &#8211; another dead end: while we could indeed set a non-standard button color, this property does not enable the tinting effect (lighter half at top, darker at bottom). Needless to say, in our case this property had the default (gray) value.</li>
<li><b>Selected</b> &#8211; this property does not really highlight the control, but rather draws a thick dashed border around it (see below).</li>
<li>focus &#8211; by calling <i><b>uicontrol</b>(hButton)</i> we can have Matlab set the focus on the button. The Operating System then automatically kicks in to add some shading effect. This finally looked close, but again, it was just not quite right.</li>
</ul>
<p><center><figure style="width: 240px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Highlight (left); focus (center); Selected (right)" src="https://undocumentedmatlab.com/images/button_highlight2.png" title="Highlight (left); focus (center); Selected (right)" width="230" height="30" /><figcaption class="wp-caption-text">Highlight (left); focus (center); Selected (right)</figcaption></figure></center></p>
<h3 id="highlighting">Solution of the highlighting mystery</h3>
<p>So maybe GUIDE attached some funky property value to the control? Let&#8217;s investigate. Remembering that the GUIDE-generated <a target="_blank" href="/articles/fig-files-format/">*.fig file is simply a standard MAT file</a> with a different extension, we can load it into the Matlab workspace and dissect it. Drilling down the GUI hierarchy we find:</p>
<pre lang='matlab' highlight='11'>
>> data = load('myGUI.fig', '-mat')
data =
    hgS_070000: [1x1 struct]
>> d.hgS_070000.children(9).properties
ans =
              Units: 'pixels'
           Callback: [function_handle]
           Position: [20 20 60 20]
             String: 'Yes'
              Value: 1
    ApplicationData: [1x1 struct]
>> d.hgS_070000.children(10).properties
ans =
              Units: 'pixels'
           Callback: [function_handle]
           Position: [100 20 60 20]
             String: 'No'
    ApplicationData: [1x1 struct]
</pre>
<p>When we compare the information that GUIDE stored for the two buttons we see that it stored an extra Value property for the &#8216;Yes&#8217; button, and used the <a target="_blank" href="/articles/getting-default-hg-property-values/">default HG value</a> for the &#8216;No&#8217; button. Let&#8217;s compare the property values in run-time (I&#8217;m using my <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/14395-objdiff-generic-object-comparator">objDiff utility</a> for this):</p>
<pre lang='matlab' highlight='10'>
>> hButton1 = findall(gcf, 'String', 'Yes');
>> hButton2 = findall(gcf, 'String', 'No');
>> props1 = get(hButton1);
>> props2 = get(hButton2);
>> objdiff(props1, props2)
ans =
      Extent: {[0 0 24 19]  [0 0 17 19]}
    Position: {[20 20 60 20]  [100 20 60 20]}
      String: {'Yes'  'No'}
       Value: {[1]  [0]}
</pre>
<p>This pretty much nails it: pushbutton highlighting is controlled via the <b>Value</b> property. According to the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/uicontrol_props.html#bqxoir7">official documentation</a>, the <b>Value</b> property has no meaning for push-buttons, only for other uicontrol styles. This is obviously not so:</p>
<pre lang='matlab'>
set(hButton, 'Value', 1);   % Turn button highlighting on
set(hButton, 'Value', 0);   % Turn button highlighting off (can use any value ~=1)
</pre>
<h3 id="Technical">Under the hood</h3>
<p>Under the hood, updating the <b>Value</b> property sets the pushbutton&#8217;s <a target="_blank" href="/articles/findjobj-find-underlying-java-object/">underlying Java control</a>&#8216;s <b>Selected</b> property to true. Note that the Java <b>Selected</b> property is entirely unrelated to Matlab&#8217;s <b>Selected</b> property (which has no underlying Java counterpart). I do not understand the design decision that let to this, but since it has been like this for many years I see little chance that it will be changed in the near future.<br />
In any case, the Java <b>Selected</b> property indeed has a visual effect, but the actual effect depends on the current operating system and Look-&amp;-Feel (LnF). You can <a target="_blank" href="/articles/modifying-matlab-look-and-feel/">play around with the LnF</a> to achieve various other alternative highlighting effects, or customize one of your own.</p>
<h3 id="seminar">Advanced Matlab GUI course &#8211; London 12-14 March, 2014</h3>
<p>If this topic has piqued your interest, consider joining my <a target="_blank" href="/training/advanced-matlab-seminars-london-10-14-march-2014/">Advanced Matlab GUI course</a> in London on 12-14 March, 2014. In this course/seminar I will explore numerous other ways by which we can customize Matlab&#8217;s GUI and graphics in ways that you never knew were even possible! This is a unique opportunity to take your Matlab skills to a higher level within just a few days. This training is not offered anywhere else.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/undocumented-button-highlighting">Undocumented button highlighting</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/borderless-button-used-for-plot-properties" rel="bookmark" title="Borderless button used for plot properties">Borderless button used for plot properties </a> <small>A borderless button can be used to add unobtrusive functionality to plot axes...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/toolbar-button-labels" rel="bookmark" title="Toolbar button labels">Toolbar button labels </a> <small>GUI toolbar button labels can easily be set and customized using underlying Java components. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/button-customization" rel="bookmark" title="Button customization">Button customization </a> <small>Matlab's button uicontrols (pushbutton and togglebutton) are basically wrappers for a Java Swing JButton object. This post describes how the buttons can be customized using this Java object in ways that are impossible using pure Matlab....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/hgs-undocumented-parameters-interface" rel="bookmark" title="HG&#039;s undocumented parameters interface">HG&#039;s undocumented parameters interface </a> <small>Some HG functions also accept inputs parameters in a struct fields rather than the normal P-V pairs format. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/undocumented-button-highlighting/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>A couple of internal Matlab bugs and workarounds</title>
		<link>https://undocumentedmatlab.com/articles/couple-of-bugs-and-workarounds?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=couple-of-bugs-and-workarounds</link>
					<comments>https://undocumentedmatlab.com/articles/couple-of-bugs-and-workarounds#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 12 Jun 2013 18:00:23 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[GUIDE]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3865</guid>

					<description><![CDATA[<p>A couple of undocumented Matlab bugs have simple workarounds. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/couple-of-bugs-and-workarounds">A couple of internal Matlab bugs and workarounds</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/couple-of-matlab-bugs-and-workarounds" rel="bookmark" title="Another couple of Matlab bugs and workarounds">Another couple of Matlab bugs and workarounds </a> <small>A couple of internal Matlab bugs and their workarounds. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation" rel="bookmark" title="Matlab&#039;s internal memory representation">Matlab&#039;s internal memory representation </a> <small>Matlab's internal memory structure is explored and discussed. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations" rel="bookmark" title="Internal Matlab memory optimizations">Internal Matlab memory optimizations </a> <small>Copy-on-write and in-place data manipulations are very useful Matlab performance improvement techniques. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-internal-java-class-members" rel="bookmark" title="Accessing internal Java class members">Accessing internal Java class members </a> <small>Java inner classes and enumerations can be used in Matlab with a bit of tweaking. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Like any other major software package, Matlab too has <a target="_blank" rel="nofollow" href="http://www.mathworks.com/support/bugreports/">its share of bugs</a>. If you ask me, the number of known bugs in Matlab is actually very small compared to the industry standard. Posting bugs online saves the support staff work on duplicates and provides immediate relief for users if the bug happens to have a posted workaround. It also increases transparency, which helps customer loyalty and confidence in the product. Serious engineering work that relies on Matlab for anything from designing cars and planes to trading on stock exchanges needs to be aware of all the current bugs, in order to avoid them in the production code.<br />
Unfortunately, for some reason MathWorks does not publicize all the bugs that it knows about. I know this since there are multiple bugs that I have reported and were confirmed by the competent technical support staff, which do not appear on the online list. I do not know whether this is a deliberate MathWorks policy based on some criteria, but I would hope not and I hope it will be fixed. IMHO, Matlab in general is a very stable system that has absolutely nothing to be ashamed of in terms of the low number, and relatively low-impact, of its open bugs.<br />
Today I write about two internal Matlab bugs that I have recently discovered and reported, along with their workarounds. None of them is really critical, but since neither appears in the official bug parade (as of today), I figured it would do some public good to post them here.<br />
<span id="more-3865"></span></p>
<h3 id="clf">The <i>clf</i> function does not clear <i>javacomponent</i>s (1-MNELS1)</h3>
<p>The <i><b>clf</b></i> function clears the specified figure window (or the current figure [<i><b>gcf</b></i>] if no figure handle was specified as input) of any axes and GUI controls. At least, that what it is supposed to do and what it did pretty well until R2012a (Matlab 7.14). Apparently, in R2012b (Matlab 8.0) something broke and controls that are added to the figure window using the <a target="_blank" href="/articles/javacomponent/"><i><b>javacomponent</b></i> function</a> are no longer cleared by <i><b>clf</b></i> &#8211; all the regular Matlab axes and uicontrols are deleted, but not the Java controls.</p>
<pre lang='matlab'>
figure;
[jButton, hContainer] = javacomponent(javax.swing.JButton('Click'), [], gcf);
drawnow;
clf  % bug - clf does not delete the jButton/hContainer component from the figure
</pre>
<p>There are several possible workarounds:</p>
<ol>
<li>Keep the handles of all the relevant Java components, and then <i><b>delete</b></i> them directly:
<pre lang='matlab'>delete(hContainer)</pre>
</li>
<li>Use <i><b>findobj</b></i> to delete all components, rather than the <i><b>clf</b></i> function (we use <i><b>setdiff</b></i> to prevent deletion of the figure window itself):
<pre lang='matlab'>delete(setdiff(findobj(gcf),gcf))</pre>
</li>
</ol>
<p>Note that this bug does not occur when using <a target="_blank" href="/articles/hg2-update/">HG2</a>. However, for users who use the still-standard HG1, this bug is still unfixed as of Matlab R2013b Pre-release (which is now available for download for subscribed users).</p>
<h3 id="guide">GUIDE is unusable with <i>dbstop if error</i> (1-MH5KVI)</h3>
<p>In R2013a (Matlab 8.1) I encounter a recurring error when attempting to inspect properties of objects in GUIDE, when &#8220;<i><b>dbstop if error</b></i>&#8221; is turned on.<br />
The error happens when I have &#8220;<i><b>dbstop if error</b></i>&#8221; enabled. This is an <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/videos/2013/04/08/using-dbstop-if-error-and-conditional-breakpoints-to-debug-matlab/">enormously helpful</a> debugging tool, so I normally have it turned on in my startup.m file. But in R2013a, if I try to inspect an object&#8217;s properties in GUIDE, I see a problem. Matlab hits the breakpoint in <i>%matlabroot%/toolbox/matlab/codetools/+internal/+matlab/+inspector/SceneViewerListener.m</i> line 99 due to the fact that <i>isvalid()</i> is not defined for the object, and the inspector window remains blank.<br />
How to reproduce:</p>
<ul>
<li>run &#8220;<i><b>dbstop if error</b></i>&#8221; in the Matlab command window</li>
<li>open a <i>*.fig</i> file in the Matlab command window (e.g., &#8220;<i><b>guide myApplication.fig</b></i>&#8220;)</li>
<li>right-click and inspect the properties for an axes (for example)</li>
<li>wait for the breakpoint to occur &#8211; &#8220;K&gt;&gt;&#8221; in the command window; the Editor stops (green arrow) in <i>SceneViewerListener.m</i> line 99</li>
<li>an empty inspector window is displayed</li>
</ul>
<p>Analysis:<br />
Because <i>SceneViewerListener</i> is called from Java, not Matlab, the error is thrown as an exception that is trapped by the Java code and therefore does not appear to the user unless &#8220;<i><b>dbstop if error</b></i>&#8221; is on. Here is the full stack trace at the point of error (see <a target="_blank" href="/articles/java-stack-traces-in-matlab/">this post</a> regarding how to generate the Java stack dump):</p>
<pre lang='matlab'>
K>> dbstack
> In SceneViewerListener>SceneViewerListener.isBeingDeleted at 99
K>> st = java.lang.Thread.currentThread.getStackTrace; for idx = 2 : length(st), disp(st(idx)); end
com.mathworks.jmi.NativeMatlab.SendMatlabMessage(Native Method)
com.mathworks.jmi.NativeMatlab.sendMatlabMessage(NativeMatlab.java:219)
com.mathworks.jmi.MatlabLooper.sendMatlabMessage(MatlabLooper.java:120)
com.mathworks.jmi.Matlab.mtFeval(Matlab.java:1540)
com.mathworks.mlwidgets.inspector.JidePropertyViewTable.isBeingDeleted(JidePropertyViewTable.java:154)
com.mathworks.mlwidgets.inspector.JidePropertyViewTable.filterOutInvalidObjects(JidePropertyViewTable.java:170)
com.mathworks.mlwidgets.inspector.JidePropertyViewTable.setObjects_MatlabThread(JidePropertyViewTable.java:187)
com.mathworks.mlwidgets.inspector.PropertyView.setObject_MatlabThread(PropertyView.java:655)
com.mathworks.mlwidgets.inspector.PropertyView.setObject_AnyThread(PropertyView.java:591)
com.mathworks.mlwidgets.inspector.PropertyView.access$1300(PropertyView.java:37)
com.mathworks.mlwidgets.inspector.PropertyView$RegistryHandler.itemStateChanged(PropertyView.java:698)
java.awt.AWTEventMulticaster.itemStateChanged(Unknown Source)
com.mathworks.services.ObjectRegistry.fireItemEvent(ObjectRegistry.java:763)
com.mathworks.services.ObjectRegistry.setSelected(ObjectRegistry.java:700)
com.mathworks.services.ObjectRegistry.setSelected(ObjectRegistry.java:617)
com.mathworks.mde.inspector.Inspector.setSelected(Inspector.java:584)
com.mathworks.mde.inspector.Inspector.inspectObjectArray(Inspector.java:569)
com.mathworks.mde.inspector.Inspector.inspectObjectArray(Inspector.java:520)
com.mathworks.mde.inspector.Inspector$11.run(Inspector.java:478)
com.mathworks.jmi.NativeMatlab.dispatchMTRequests(NativeMatlab.java:347)
</pre>
<p>Workaround:<br />
replace the existing code of <i>SceneViewerListener.m</i>:</p>
<pre lang='matlab'>
>> edit internal.matlab.inspector.SceneViewerListener
...
if ~isvalid(selectedObject)
    beingDeleted = true;
elseif isprop(selectedObject,'BeingDeleted') && strcmp('on',selectedObject.BeingDeleted)
    beingDeleted = true;
elseif ~isempty(ancestor(selectedObject,'figure')) && strcmp('on',get(ancestor(selectedObject,'figure'),'BeingDeleted'))
    beingDeleted = true;
else
    beingDeleted = false;
end
</pre>
<p>with the following (changed lines are highlighted):</p>
<pre lang='matlab' highlight='1-3'>
if any(~isobject(selectedObject))
    beingDeleted = false;
elseif ~isValid
    beingDeleted = true;
elseif isprop(selectedObject,'BeingDeleted') && strcmp('on',selectedObject.BeingDeleted)
    beingDeleted = true;
elseif ~isempty(ancestor(selectedObject,'figure')) && strcmp('on',get(ancestor(selectedObject,'figure'),'BeingDeleted'))
    beingDeleted = true;
else
    beingDeleted = false;
end
</pre>
<p>It looks like this bug was apparently fixed in the R2013b Pre-release without needing to modify <i>SceneViewerListener</i>. But if you still encounter this problem you now know what to do.<br />
I have reported another GUIDE-related bug, but I do not have a workaround for this one: If you run the GUI from within GUIDE, and some uncaught error (exception) occurs, then from that moment onward you cannot save any modifications to the figure file in that session.<br />
Do you know of any other undocumented bugs, preferably with workarounds? If so, please post them in a comment <a href="/articles/couple-of-bugs-and-workarounds/#respond">here</a>.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/couple-of-bugs-and-workarounds">A couple of internal Matlab bugs and workarounds</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/couple-of-matlab-bugs-and-workarounds" rel="bookmark" title="Another couple of Matlab bugs and workarounds">Another couple of Matlab bugs and workarounds </a> <small>A couple of internal Matlab bugs and their workarounds. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlabs-internal-memory-representation" rel="bookmark" title="Matlab&#039;s internal memory representation">Matlab&#039;s internal memory representation </a> <small>Matlab's internal memory structure is explored and discussed. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations" rel="bookmark" title="Internal Matlab memory optimizations">Internal Matlab memory optimizations </a> <small>Copy-on-write and in-place data manipulations are very useful Matlab performance improvement techniques. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-internal-java-class-members" rel="bookmark" title="Accessing internal Java class members">Accessing internal Java class members </a> <small>Java inner classes and enumerations can be used in Matlab with a bit of tweaking. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/couple-of-bugs-and-workarounds/feed</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>Common javacomponent problems</title>
		<link>https://undocumentedmatlab.com/articles/common-javacomponent-problems?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=common-javacomponent-problems</link>
					<comments>https://undocumentedmatlab.com/articles/common-javacomponent-problems#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 07 Dec 2011 18:00:38 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Semi-documented function]]></category>
		<category><![CDATA[Callbacks]]></category>
		<category><![CDATA[GUIDE]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2607</guid>

					<description><![CDATA[<p>The javacomponent function is very useful for placing Java components on-screen, but has a few quirks. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/common-javacomponent-problems">Common javacomponent problems</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/javacomponent" rel="bookmark" title="The javacomponent function">The javacomponent function </a> <small>Matlab's built-in javacomponent function can be used to display Java components in Matlab application - this article details its usages and limitations...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/javacomponent-background-color" rel="bookmark" title="Javacomponent background color">Javacomponent background color </a> <small>This article explains how to align Java component background color with a Matlab color....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/ip-address-input-control" rel="bookmark" title="IP address input control">IP address input control </a> <small>A built-in JIDE control can be used in Matlab GUI for IP-address entry/display. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/editable-combo-box" rel="bookmark" title="Editable combo-box">Editable combo-box </a> <small>Matlab's popup menu (combo-box) control is quite limited in its abilities. This article explains how we can work around these limitations. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>The <i><b>javacomponent</b></i> function, which I described <a target="_blank" href="/articles/javacomponent/">here</a> last year, is a very important built-in Matlab function that enables placing Java components in Matlab figure GUI. Using <i><b>javacomponent</b></i> is pretty straight-forward. However, there are a few quirks that users should be aware of. In today&#8217;s article I&#8217;ll try to highlight some of them and discuss workarounds.</p>
<h3 id="figure-vis">Figure visibility</h3>
<p>Java components can only be placed onscreen when their containing Matlab figure has been made visible. This means that calls to <i><b>javacomponent</b></i> cannot be placed at the GUIDE-created *_OpeningFcn() function, because that function is invoked <i>before</i> the figure window is made visible.<br />
Of course, we can always force the figure to become visible by setting the figure&#8217;s <b>Visible</b> property to <code>'on'</code> in this function, before calling our <i><b>javacomponent</b></i>s. But IMHO, a better option would be to simply place the <i><b>javacomponent</b></i>s in the corresponding GUIDE-created *_OutputFcn() function, which is invoked <i>after</i> the figure window is made visible.</p>
<h3 id="parent-vis">Auto-hiding with parent container</h3>
<p>Java components are not automatically hidden with their ancestor container panel. This is also the root cause of the failure of Java components to disappear when switching tabs in a <i><b>uitab</b></i>.<br />
One simple workaround for this that I often use is to link the <b>Visible</b> properties of the <i><b>javacomponent</b></i> container and the parent container:</p>
<pre lang='matlab'>
jButton = javax.swing.JButton('click me!');
[jhButton, hContainer] = javacomponent(jButton, [100,100,60,30], hParent);
setappdata(hParent, 'linked_props__', linkprop([hParent,hContainer],'Visible'));
</pre>
<p>This has indeed been fixed in R2010b. If you ask me, this should have been standard behavior of <i><b>javacomponent</b></i> since the very beginning&#8230;<br />
Although there is no need for the workaround in R2010b onward, I usually keep the workaround because it doesn&#8217;t hurt and enables backward compatibility for users who may have an older Matlab release.</p>
<h3 id="parent-types">Possible parent container types</h3>
<p><i><b>javacomponent</b></i> accepts parent handles that are figures, toolbars, <i><b>uipanel</b></i>s, or <a target="_blank" href="/articles/matlab-layout-managers-uicontainer-and-relatives"><i><b>uicontainer</b></i>s</a> (some of these are not documented as possible parents in some Matlab releases, but they are). Since R2008a, parents of type <a target="_blank" href="/articles/uisplittool-uitogglesplittool/"><i><b>uisplittool</b></i> and <i><b>uitogglesplittool</b></i></a> can also be used. Unfortunately, frames are not <i><b>uicontainer</b></i>s and, therefore, cannot be used as <i><b>javacomponent</b></i> parents.<br />
Note: Due to a bug in R2007a, <i><b>javacomponent</b></i>s cannot be added to <i><b>uicontainer</b></i>s, since <i>javacomponent.m</i> checks if <code>isa(hParent,'uicontainer')</code> (and similarly for <code>'uiflowcontainer', 'uigridcontainer'</code>), instead of <code>isa(hParent,'hg.uicontainer')</code> (and similarly for the others). If we modify <i>javacomponent.m</i> accordingly (add &#8220;hg.&#8221; in lines 98-100), this bug will be fixed. Since R2007b, <code>isa(…,'hg.uicontainer')</code> is equivalent to <code>isa(…,'uicontainer')</code>, so this fix is unnecessary.</p>
<h3 id="inputs">Input parameters</h3>
<p>Unlike many other Matlab functions, <i><b>javacomponent</b></i> does not accept optional parameter-value (P-V) pairs. If we want to customize the appearance of the Java component, it is better to create it , customize it, and only then to present it onscreen using <i><b>javacomponent</b></i>. If we first present the component and then customize it, there might be all sorts of undesirable flicker effects while the component is changing its properties.<br />
One of the parameters that unfortunately cannot be customized before calling <i><b>javacomponent</b></i> is the component&#8217;s position onscreen. <i><b>javacomponent</b></i> only accepts a position vector in pixel units. To modify the component to use normalized units, we need to modify the container&#8217;s properties:</p>
<pre lang='matlab'>
jButton = javax.swing.JButton('click me!');
[jhButton, hContainer] = javacomponent(jButton, [100,100,60,30], gcf);
set(hContainer, 'Units','norm');
</pre>
<p>Similarly, we can set the container&#8217;s <b>UserData</b> and <b>ApplicationData</b> only after the call to <i><b>javacomponent</b></i>.</p>
<h3 id="bg-color">Background color</h3>
<p>The default background color of <i><b>javacomponent</b></i>s is a slightly different shade of gray than the default <i><b>uicontrol</b></i> background color. Please refer to my recent <a target="_blank" href="/articles/javacomponent-background-color/">article</a> for a detailed discussion of this issue.</p>
<h3 id="alignment">Vertical alignment</h3>
<p>Java components are slightly mis-aligned vertically with combo-box (<b>Style</b>=&#8217;popup&#8217;) <i><b>uicontrol</b></i>s, even when positioned using the same Y position. This is actually due to an apparent bug in Matlab&#8217;s implementation of the combo-box <i><b>uicontrol</b></i>, and not in the Java component&#8217;s: Apparently, the Matlab control does not obey its specified height and uses some other default height.<br />
If we place <i><b>javacomponent</b></i>s side-by-side with a regular Matlab popup <i><b>uicontrol</b></i>s and give them all the same Y position, we can see this mis-alignment. It is only a few pixels, but the effect is visible and disturbing. To fix it, we need to add a small offset to the <i><b>javacomponent</b></i>&#8216;s container&#8217;s <b>Position</b> property to make both the initial Y position slightly lower, and the height value slightly higher than the values for the corresponding Matlab combo-box control.</p>
<h3 id="callbacks">Callbacks</h3>
<p>Unlike Matlab <i><b>uicontrol</b></i> callbacks, Java callbacks are activated even when the affected value does not change. Therefore, setting a value in the component&#8217;s callback could well cause an infinite loop of invoked callbacks.<br />
Matlab programmers often use the practice of modifying component value within the callback function, as a means of fixing user-entered values to be within a certain data range, or in order to format the displayed value. This is relatively harmless in Matlab (if done correctly) since updating a Matlab <i><b>uicontrol</b></i>&#8216;s value to the current value does not retrigger the callback. But since this is not the case with Java callbacks, users should beware not to use the same practice there. In cases where this cannot be avoided, users should at least implement some sort of <a target="_blank" href="/articles/controlling-callback-re-entrancy/">callback re-entrancy prevention logic</a>.</p>
<h3 id="EDT">EDT</h3>
<p>Java components typically need to use the independent Java Event processing Thread (EDT). EDT is very important for Matlab GUI, as explained in <a target="_blank" href="/articles/matlab-and-the-event-dispatch-thread-edt/">this article</a>. Failure to use EDT properly in Matlab can lead to unexpected GUI behavior and even Matlab hangs or crashes.<br />
If the <i><b>javacomponent</b></i> function is called in a very specific syntax format where the first input arg is a string (the name of the Java class to be created), then the newly-created component is placed on the EDT. However, this is not the normal manner in which <i><b>javacomponent</b></i> is used: A much more typical use-case is where <i><b>javacomponent</b></i> is passed a reference handle to a previously-created Java component. In such cases, it is the user&#8217;s responsibility to place the component on the EDT. Until R2008a this should be done using the <i><b>awtcreate</b></i> function; since R2008b, we can use the much simpler <i><b>javaObjectEDT</b></i> function (<i><b>javaObjectEDT</b></i> actually existed since R2008a, but was buggy on that release so I suggest using it only starting in R2008b; it became documented starting in R2009a). In fact, modern <i><b>javacomponent</b></i> saves us the trouble, by automatically using <i><b>javaObjectEDT</b></i> to auto-delegate the component onto the EDT, even if we happen to have created it on the MT.<br />
The paragraph above may lead us to believe that we only need to worry about EDT in R2008a and earlier. Unfortunately, this is not the case. Modern GUI requires using many sub-components, that are attached to their main component (e.g., CellRenderers and CellEditors). <i><b>javacomponent</b></i> only bothers to place the main component on the EDT &#8211; not any of the sub-components. We need to handle these separately. Liberally auto-delegating components to the EDT seems like a safe and painless habit to have.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/common-javacomponent-problems">Common javacomponent problems</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/javacomponent" rel="bookmark" title="The javacomponent function">The javacomponent function </a> <small>Matlab's built-in javacomponent function can be used to display Java components in Matlab application - this article details its usages and limitations...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/javacomponent-background-color" rel="bookmark" title="Javacomponent background color">Javacomponent background color </a> <small>This article explains how to align Java component background color with a Matlab color....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/ip-address-input-control" rel="bookmark" title="IP address input control">IP address input control </a> <small>A built-in JIDE control can be used in Matlab GUI for IP-address entry/display. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/editable-combo-box" rel="bookmark" title="Editable combo-box">Editable combo-box </a> <small>Matlab's popup menu (combo-box) control is quite limited in its abilities. This article explains how we can work around these limitations. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/common-javacomponent-problems/feed</wfw:commentRss>
			<slash:comments>29</slash:comments>
		
		
			</item>
		<item>
		<title>handle2struct, struct2handle &#038; Matlab 8.0</title>
		<link>https://undocumentedmatlab.com/articles/handle2struct-struct2handle-and-matlab-8?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=handle2struct-struct2handle-and-matlab-8</link>
					<comments>https://undocumentedmatlab.com/articles/handle2struct-struct2handle-and-matlab-8#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 29 Dec 2010 18:00:56 +0000</pubDate>
				<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Semi-documented function]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[GUIDE]]></category>
		<category><![CDATA[HG2]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[Menubar]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Toolbar]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2023</guid>

					<description><![CDATA[<p>This article explains how we can use a couple of undocumented functions in Matlab GUI, and what we can learn from this about Matlab's future.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/handle2struct-struct2handle-and-matlab-8">handle2struct, struct2handle &amp; Matlab 8.0</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/undocumented-scatter-plot-behavior" rel="bookmark" title="Undocumented scatter plot behavior">Undocumented scatter plot behavior </a> <small>The scatter plot function has an undocumented behavior when plotting more than 100 points: it returns a single unified patch object handle, rather than a patch handle for each specific point as it returns with 100 or less points....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/fig-files-format" rel="bookmark" title="FIG files format">FIG files format </a> <small>FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-layout-managers-uicontainer-and-relatives" rel="bookmark" title="Matlab layout managers: uicontainer and relatives">Matlab layout managers: uicontainer and relatives </a> <small>Matlab contains a few undocumented GUI layout managers, which greatly facilitate handling GUI components in dynamically-changing figures....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-hg2" rel="bookmark" title="Matlab&#039;s HG2 mechanism">Matlab&#039;s HG2 mechanism </a> <small>HG2 is presumably the next generation of Matlab graphics. This article tries to explore its features....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Last week I explained that <a target="_blank" href="/articles/fig-files-format/">FIG files are simply MAT files in disguise</a>. Today, we look under the hood of Matlab&#8217;s <i><b>hgsave</b></i> function, which is used to save FIG files. We shall see that this is both useful and illuminating vis-a-vis Matlab&#8217;s future.</p>
<h3 id="handle2struct">handle2struct</h3>
<p>Under the hood, <i><b>hgsave</b></i> uses the <a target="_blank" href="/articles/legend-semi-documented-feature/#Semi-documented">semi-documented</a> built-in <i><b>handle2struct</b></i> function to convert the figure handle into a Matlab <i><b>struct</b></i> that is then stored with a simple <i><b>save</b></i> (the same function that saves MAT files) function call.<br />
The fact that <i><b>handle2struct</b></i> is semi-documented means that the function is explained in a help comment (which can be seen via the <i><b>help</b></i> command), that is nonetheless not part of the official doc sections. It is an unsupported feature originally intended only for internal Matlab use (which of course doesn&#8217;t mean we can&#8217;t use it).<br />
<i><b>handle2struct</b></i> merits a dedicated mention, since I can envision several use-cases for storing only a specific GUI handle (for example, a <i><b>uipanel</b></i>, a specific graph, or a set of GUI controls&#8217; state). In this case, all we need to do is to call <i><b>handle2struct</b></i> with the requested parent handle, then <i><b>save</b></i> the returned structure. So simple, so powerful. <i><b>handle2struct</b></i> automatically returns all the non-default property information, recursively in all the handle&#8217;s children.<br />
Note that features that are not properties of displayed handles (camera position, 3D rotation/pan/zoom states, annotations, axes-linking etc.) are not processed by <i><b>handle2struct</b></i>. For storing the states of these features, you need to use some specific handling &#8211; see the code within %matlabroot%\toolbox\matlab\graphics\private\hgsaveStructDbl.m for details. Basically, hgsaveStructDbl.m reads the state of all these features and temporarily stores them in the base handle&#8217;s <strong>ApplicationData</strong> property; <i><b>handle2struct</b></i> then reads them as any other regular handle property data, and then hgsaveStructDbl.m clears the temporary data from the handle&#8217;s <strong>ApplicationData</strong>. We can use the same trick for any other application state, of course.</p>
<h3 id="struct2handle">struct2handle</h3>
<p><i><b>handle2struct</b></i> has a reverse function &#8211; the semi-documented <i><b>struct2handle</b></i>. I use it for creating dynamic preference panels: As in Matlab&#8217;s Preferences window, I have a list of preference topics and a set of corresponding options panels. In my case, it was easy to design each panel as a separate FIG file using GUIDE. In run-time, I simply load the relevant panel from its FIG file as described above, and place it onscreen in a dedicated <i><b>uipanel</b></i> using <i><b>struct2handle</b></i>. This enables very easy maintenance of preference panels, without sacrificing any functionality.<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Matlab's preferences panels" src="https://undocumentedmatlab.com/images/FIG_MAT.png" title="Matlab's preferences panels" width="450" height="274" /><figcaption class="wp-caption-text">Matlab's preferences panels</figcaption></figure></center><br />
Figure menus and toolbars are not normally stored by <i><b>hgsave</b></i>, unless you use the optional &#8216;all&#8217; parameter (and correspondingly in <i><b>hgload</b></i>, if you choose to use it). <i><b>handle2struct</b></i> and <i><b>handle2struct</b></i> accept the same optional &#8216;all&#8217; parameter as <i><b>hgsave</b></i> and <i><b>hgload</b></i>. Unfortunately, a warning message indicates that this option will be discontinued in some future Matlab version.<br />
Which brings us to our final topic for today:</p>
<h3 id="Matlab8">Matlab 8: Boldly going where no FIG has gone before&#8230;</h3>
<p>Remember my post earlier this year about the <a target="_blank" href="/articles/matlab-hg2/">new HG2 mechanism</a>? I speculated that when MathWorks decides to release HG2, it will define this as a major Matlab release and label it Matlab 8.0.<br />
The source code in hgsave.m appears to confirm my speculation. Here is the relevant code section (slightly edited for clarity), which speaks for itself:</p>
<pre lang="matlab">
% Decide which save code path to use
if ~feature('HGUsingMatlabClasses')   % <== existing HG
    % Warn if user passed in 'all' flag
    if SaveAll
        warning( 'MATLAB:hgsave:DeprecatedOption', ...
            'The ''all'' option to hgsave will be removed in a future release.');
    end
    hgS = hgsaveStructDbl(h, SaveAll);
    SaveVer = '070000';
    SaveOldFig = true;
else   % <== HG2
    % Warn if user passed in 'all' flag
    if SaveAll
        warning( 'MATLAB:hgsave:DeprecatedOption', ...
            'The ''all'' option to hgsave has been removed.');
    end
    if SaveOldFig
        hgS = hgsaveStructClass(h);
        SaveVer = '080000';
    else
        hgO = hgsaveObject(h);
        SaveVer = '080000';
    end
end
% Revision encoded as 2 digits for major revision,
% 2 digits for minor revision, and 2 digits for
% patch revision.  This is the minimum revision
% required to fully support the file format.
% e.g. 070000 means 7.0.0
</pre>
<p>As can be seen, when Matlab starts using HG2 (perhaps in 2011?), the top-level structure node will be called "hgS_080000", indicating Matlab 8.0. QED.<br />
As a side-note, note that in HG2/Matlab8, although the comment about using 'all' indicates that it has been removed, in practice it is still accepted (although not being used). This will enable your code to be backward-compatible whenever HG2 launches, and future-compatible today.<br />
Have you used <i><b>handle2struct</b></i> or <i><b>struct2handle</b></i>? If so, please share your experience in a <a href="/articles/handle2struct-struct2handle-and-matlab-8/#respond">comment</a>.<br />
<em>Let the upcoming 2011 be a year filled with revelations, announcements and fulfillment! Happy New Year everybody!</em></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/handle2struct-struct2handle-and-matlab-8">handle2struct, struct2handle &amp; Matlab 8.0</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/undocumented-scatter-plot-behavior" rel="bookmark" title="Undocumented scatter plot behavior">Undocumented scatter plot behavior </a> <small>The scatter plot function has an undocumented behavior when plotting more than 100 points: it returns a single unified patch object handle, rather than a patch handle for each specific point as it returns with 100 or less points....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/fig-files-format" rel="bookmark" title="FIG files format">FIG files format </a> <small>FIG files are actually MAT files in disguise. This article explains how this can be useful in Matlab applications....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-layout-managers-uicontainer-and-relatives" rel="bookmark" title="Matlab layout managers: uicontainer and relatives">Matlab layout managers: uicontainer and relatives </a> <small>Matlab contains a few undocumented GUI layout managers, which greatly facilitate handling GUI components in dynamically-changing figures....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-hg2" rel="bookmark" title="Matlab&#039;s HG2 mechanism">Matlab&#039;s HG2 mechanism </a> <small>HG2 is presumably the next generation of Matlab graphics. This article tries to explore its features....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/handle2struct-struct2handle-and-matlab-8/feed</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>Matlab layout managers: uicontainer and relatives</title>
		<link>https://undocumentedmatlab.com/articles/matlab-layout-managers-uicontainer-and-relatives?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlab-layout-managers-uicontainer-and-relatives</link>
					<comments>https://undocumentedmatlab.com/articles/matlab-layout-managers-uicontainer-and-relatives#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 09 Jun 2010 22:03:32 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Semi-documented function]]></category>
		<category><![CDATA[GUIDE]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1593</guid>

					<description><![CDATA[<p>Matlab contains a few undocumented GUI layout managers, which greatly facilitate handling GUI components in dynamically-changing figures.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-layout-managers-uicontainer-and-relatives">Matlab layout managers: uicontainer and relatives</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/tab-panels-uitab-and-relatives" rel="bookmark" title="Tab panels &#8211; uitab and relatives">Tab panels &#8211; uitab and relatives </a> <small>This article describes several undocumented Matlab functions that support tab-panels...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-the-matlab-desktop-layout-programmatically" rel="bookmark" title="Setting the Matlab desktop layout programmatically">Setting the Matlab desktop layout programmatically </a> <small>The Matlab desktop enables saving and switching layouts using the main menu. This post shows how to do so programmatically....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/listbox-layout-customization" rel="bookmark" title="Listbox layout customization">Listbox layout customization </a> <small>Matlab's listbox layout can be modified to display multiple item columns and different inter-cell margins. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/common-javacomponent-problems" rel="bookmark" title="Common javacomponent problems">Common javacomponent problems </a> <small>The javacomponent function is very useful for placing Java components on-screen, but has a few quirks. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>When designing Matlab applications, we can either use Matlab&#8217;s designer (<a target="_blank" href="/articles/guide-customization/"><i><b>guide</b></i></a>), or manually position each GUI component programmatically, using its <strong>Position</strong> property. Matlab lacks the layout managers so common in Java, that enable easy relative component positioning, taking into account dynamic container size, components spacing weights etc. Of course, we can always trap the container&#8217;s <strong>ResizeFcn</strong> callback to update our layout, but doing so is one royal pain in the so-and-so&#8230;<br />
Luckily, there is (of course) an undocumented solution to this problem, and at <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/279442#736318">the public&#8217;s demand</a> I will detail it below. It doesn&#8217;t solve all layout-management needs, but it goes a long way. Most importantly, it uses <strong>pure Matlab</strong> &#8211; no Java knowledge whatsoever is needed.</p>
<h3 id="uicontainer"><i>uicontainer</i></h3>
<p>Matlab&#8217;s uicontainer family (<i><b>uicontainer</b></i>, <i><b>uiflowcontainer</b></i> and <i><b>uigridcontainer</b></i>) consists of container objects that enable customizable layout management of contained components. Uicontainers can contain any Matlab component that may have a <i><b>uipanel</b></i> handle as a <b>Parent</b> property. This includes uicontrols, plot axes etc., as well as other uicontainers.<br />
The basic <i><b>uicontainer</b></i> object appears to be little more than a transparent container for contained objects. It can be used interchangeably with <i><b>uipanel</b></i>, which appears to be a specialized type of a <i><b>uicontainer</b></i>. Indeed, as MathWorks <a target="_blank" rel="nofollow" href="http://www.mathworks.com/support/solutions/en/data/1-OQBBH/">notes</a>:<br />
<q>The UICONTAINER function is undocumented, and is not intended for direct use. The UIPANEL function should be used instead, as it provides more functionality.</q><br />
In some cases, Matlab itself uses <i><b>uicontainer</b></i> instead of <i><b>uipanel</b></i>: for example, ActiveX controls are enclosed within transparent <i><b>uicontrol</b></i> objects when added to a figure:</p>
<pre lang="matlab">
>> [hActivex,hContainer] = actxcontrol('OWC11.Spreadsheet.11');
>> get(hContainer,'Type')
ans =
uicontainer
</pre>
<p><i><b>uicontainer</b></i> objects are not very customizable. For example, unlike <i><b>uipanel</b></i>s, <i><b>uicontainer</b></i>s have no titles or borders. We would therefore usually prefer to use <i><b>uipanel</b></i>s, as Mathworks suggested above. An exception to this rule is a case where we need to derive our own customized container class. An example of this is found in %matlabroot%/toolbox/matlab/uitools/@uitools/@uitab/schema.m, which derives <i><b>uicontainer</b></i> to create a <i><b>uitab</b></i> container (which will be described in a future article).<br />
Relatives of <i><b>uicontainer</b></i> are more useful in general: <i><b>uiflowcontainer</b></i>s and <i><b>uigridcontainer</b></i>s act similarly to Java&#8217;s layout managers – specifically, <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/layout/flow.html">FlowLayout</a> and <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/layout/grid.html">GridLayout</a>. I expect to see additional layout managers incarnated within Matlab <i><b>uicontainer</b></i>s in future Matlab versions (perhaps in the R2010b pre-release that came out today &#8211; I can&#8217;t wait to see&#8230;).</p>
<h3 id="uiflowcontainer"><i>uiflowcontainer</i></h3>
<p><i><b>uiflowcontainer</b></i> is a <i><b>uicontainer</b></i> that enables adding <i><b>uicontrol</b></i>s to the container without specifying an exact position as would be required for <i><b>uicontainer</b></i> or <i><b>uipanel</b></i> (actually, positions may be specified, but they are simply ignored).<br />
By default, objects are added from the top-left corner, depending on the <i><b>uiflowcontainer</b></i>&#8216;s available space and dimensions: if width > height then rightward, otherwise downward. If the container&#8217;s dimensions change, for example by resizing the figure window, then the container&#8217;s components will automatically be resized accordingly:</p>
<pre lang="matlab">
hc = uiflowcontainer('Units','norm','Position',[.1,.1,.8,.8]);
h1 = uicontrol('string','1','parent',hc);
h2 = uicontrol('string','2','parent',hc);
h3 = uicontrol('string','3','parent',hc);
</pre>
<p><center><figure style="width: 199px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="'Auto' - before resizing figure" src="https://undocumentedmatlab.com/images/uiflowcontainer1.png" title="'Auto' - before resizing figure" width="199" height="178" /><figcaption class="wp-caption-text">'Auto' - before resizing figure</figcaption></figure> <figure style="width: 154px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="…and after resizing" src="https://undocumentedmatlab.com/images/uiflowcontainer2.png" title="…and after resizing" width="154" height="178" /><figcaption class="wp-caption-text">…and after resizing</figcaption></figure></center><br />
The components flow direction within the container may be modified by setting the <i><b>uiflowcontainer</b></i>&#8216;s <strong>FlowDirection</strong> property from its default value of &#8216;Auto&#8217; to &#8216;AutoReverse&#8217;, &#8216;BottomUp&#8217;, &#8216;TopDown&#8217;, &#8216;LeftToRight&#8217;, or &#8216;RightToLeft&#8217;:</p>
<pre lang="matlab">
set(hc,'FlowDirection','BottomUp')
set(hc,'FlowDirection','RightToLeft')
</pre>
<p><center><figure style="width: 154px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="'BottomUp'" src="https://undocumentedmatlab.com/images/uiflowcontainer3.png" title="'BottomUp'" width="154" height="178" /><figcaption class="wp-caption-text">'BottomUp'</figcaption></figure> <figure style="width: 154px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="'RightToLeft'" src="https://undocumentedmatlab.com/images/uiflowcontainer4.png" title="'RightToLeft'" width="154" height="178" /><figcaption class="wp-caption-text">'RightToLeft'</figcaption></figure></center><br />
Spacing between the components and the container&#8217;s border, and between themselves, may be controlled via the <strong>Margin</strong> property. By default, <strong>Margin</strong> is set to 2 (pixels):<br />
<center><figure style="width: 154px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Margin = 2 (default)" src="https://undocumentedmatlab.com/images/uiflowcontainer3.png" title="Margin = 2 (default)" width="154" height="178" /><figcaption class="wp-caption-text"><strong>Margin</strong> = 2 (default)</figcaption></figure> <figure style="width: 154px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Margin = 10" src="https://undocumentedmatlab.com/images/uiflowcontainer5.png" title="Margin = 10" width="154" height="178" /><figcaption class="wp-caption-text"><strong>Margin</strong> = 10</figcaption></figure></center><br />
The advantage of using <i><b>uiflowcontainer</b></i> is its automatic resizing and positioning of components. Notice how we simply specified the <i><b>uiflowcontainer</b></i>&#8216;s handle as the control&#8217;s parent, and got all this functionality out-of-the-box!<br />
If we need to use fixed-dimensions components, we can use <i><b>uicontrol</b></i>&#8216;s undocumented properties <strong>HeightLimits</strong> and <strong>WidthLimits</strong>, each of which is a 2-element numeric vector specifying the minimal and maximal allowed value for the height or width (both of these vectors are [2,Inf] by default). <i><b>uiflowcontainer</b></i> tries to accommodate the requested limits by stretching or compressing its components (we need to resize the figure for the component resizing to become visible):</p>
<pre lang="matlab">
set(h1, 'HeightLimits',[10,20], 'WidthLimits',[30,30])
set(h2, 'HeightLimits',[50,50])
set(h3, 'HeightLimits',[2,inf])   % =default value
</pre>
<p><center><figure style="width: 154px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="WidthLimits set" src="https://undocumentedmatlab.com/images/uiflowcontainer6.png" title="WidthLimits set" width="154" height="187" /><figcaption class="wp-caption-text"><strong>WidthLimits</strong> set</figcaption></figure></center><br />
Sometimes, however, no amount of component resizing is enough to fully contain all components within the <i><b>uiflowcontainer</b></i>:</p>
<pre lang="matlab">
set(h2, 'WidthLimits',[150,150])
set(h3, 'HeightLimits',[50,50])  % resize figure to see effect
</pre>
<p><center><figure style="width: 155px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="WidthLimits set" src="https://undocumentedmatlab.com/images/uiflowcontainer7.png" title="WidthLimits set" width="155" height="189" /><figcaption class="wp-caption-text"><strong>WidthLimits</strong> set</figcaption></figure></center><br />
Note: uiflowcontainer normally ignores the specified limits if they would cause the component to stretch beyond the container boundaries. This happens unless the limits are identical (as in the preceding example), which informs <i><b>uiflowcontainer</b></i> that it has no judgment in the component&#8217;s dimensions.<br />
In more complex cases, consider coding your own customized class deriving from <i><b>uiflowcontainer</b></i>. An example for such a customization can be seen in %matlabroot%/toolbox/matlab/uitools/@uitools/@uitabgroup/schema.m, which derives <i><b>uiflowcontainer</b></i> to create a <i><b>uitabgroup</b></i> container.<br />
Components within a <i><b>uiflowcontainer</b></i> are ordered according to the order they were added to the container. This order can be modified by rearranging the handles in the container&#8217;s <strong>Children</strong> property, or by using the uistack function which does the same. Note that a side-effect of this is that the components dimensions are re-normalized:<br />
<center><figure style="width: 155px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="uistack(h2,'top')" src="https://undocumentedmatlab.com/images/uiflowcontainer9.png" title="uistack(h2,'top')" width="155" height="189" /><figcaption class="wp-caption-text"><i><b>uistack</b></i>(h2,'top')</figcaption></figure> <figure style="width: 155px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="uistack(h2,'bottom')" src="https://undocumentedmatlab.com/images/uiflowcontainer8.png" title="uistack(h2,'bottom')" width="155" height="189" /><figcaption class="wp-caption-text"><i><b>uistack</b></i>(h2,'bottom')<br />
</figcaption></figure></center></p>
<h3 id="uigridcontainer"><i>uigridcontainer</i></h3>
<p><i><b>uigridcontainer</b></i> is similar to <i><b>uiflowcontainer</b></i> in its specialization of the layout: in this case, the container is divided into a transparent grid of N-by-M cells (1&#215;1 by default), each of which can contain its own component:</p>
<pre lang="matlab">
hc = uigridcontainer('Units','norm','Position',[.1,.1,.8,.8]);
set(hc, 'GridSize',[2,3]);  % default GridSize is [1,1]
h1 = uicontrol('string','1','parent',hc);
h2 = uicontrol('string','2','parent',hc);
h3 = uicontrol('string','3','parent',hc);
h4 = axes('parent',hc); x = -4:.1:4; plot(h4,x,sin(x));
set(h4,'YTickLabel',[],'XTickLabel',[]);
</pre>
<p><center><figure style="width: 155px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="A 2-by-3 uigridcontainer" src="https://undocumentedmatlab.com/images/uigridcontainer1.png" title="A 2-by-3 uigridcontainer" width="155" height="186" /><figcaption class="wp-caption-text">A 2-by-3 uigridcontainer</figcaption></figure></center><br />
The grid cells relative size can be controlled via the <strong>HorizontalWeight</strong> and <strong>VerticalWeight</strong> properties (set to NaN by default). These properties should be a numeric vector the same size as the corresponding number of cells. The property values are not important – only their relative values are used to control the relative cell dimensions. The <strong>EliminateEmptySpace</strong> property (default=&#8217;off&#8217;) controls whether empty grid rows/columns are eliminated from the container or displayed. As in <i><b>uiflowcontainer</b></i>s, the <strong>Margin</strong> property controls the spacing between the internal components and borders:</p>
<pre lang="matlab">
set(hc, 'HorizontalWeight',[6,3,1], 'VerticalWeight',[0.2,0.5])
delete([h2,h3]);  % only h1,h4 remain
set(hc,'EliminateEmptySpace','on')
</pre>
<p><center><figure style="width: 130px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Non-equal grid weights" src="https://undocumentedmatlab.com/images/uigridcontainer2.png" title="Non-equal grid weights" width="132" height="162" /><figcaption class="wp-caption-text">Non-equal grid weights</figcaption></figure> <figure style="width: 140px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="EliminateEmptySpace='on'" src="https://undocumentedmatlab.com/images/uigridcontainer4.png" title="EliminateEmptySpace='on'" width="135" height="162" /><figcaption class="wp-caption-text">EliminateEmptySpace='on'</figcaption></figure> <figure style="width: 130px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="...and 'off'" src="https://undocumentedmatlab.com/images/uigridcontainer3.png" title="...and 'off'" width="135" height="162" /><figcaption class="wp-caption-text">...and 'off'</figcaption></figure></center></p>
<h3 id="alternatives">Other layout alternatives</h3>
<p>Brad Phelan of XTargets has <a target="_blank" rel="nofollow" href="http://web.archive.org/web/20071015004151/http://xtargets.com/cms/Tutorials/Matlab-Programming/Advanced-Layout-Management-With-Handle-Graphics.html">created</a> Matlab equivalents of Java&#8217;s <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/layout/border.html">BorderLayout</a> and <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/layout/spring.html">SpringLayout</a>. The advantage of using Brad&#8217;s layout managers is that they appear to have full Matlab interoperability, including the ability to add Matlab components, unlike Java&#8217;s layout managers.<br />
A File Exchange contributor named Jason has added a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/22968">GridBagLayout implementation</a>, mimicking Java&#8217;s well-known <a target="_blank" rel="nofollow" href="http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html">GridBagLayout</a>.<br />
Additional and more flexible layout managers are available in Java (one of my favorites is <a target="_blank" rel="nofollow" href="http://www.jgoodies.com/freeware/forms/">JGoodies Forms</a>, which is pre-bundled with Matlab). Just remember the limitation that no Matlab component (such as GUI controls or plot axes) can be added to Java containers. Therefore, feel free to use these Java containers as long as their contained GUI is limited to Java components (JButton, JComboBox etc.).</p>
<h3 id="uitools">Other uitools</h3>
<p>Today&#8217;s article about <i><b>uicontainer</b></i> and its relatives was the first of several posts that will describe undocumented functions that reside in the %matlabroot%/toolbox/matlab/uitools folder. Feel free to look within this folder for other interesting undocumented functions. Most of these functions are semi-documented, meaning that they have a usable help-section hidden within the m-file (type &#8220;edit uicontainer.m&#8221; for example). Many have existed more-or-less unchanged for many releases. Note that there is no guarantee that they will remain in future releases. When using unsupported functionality, always code defensively.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-layout-managers-uicontainer-and-relatives">Matlab layout managers: uicontainer and relatives</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/tab-panels-uitab-and-relatives" rel="bookmark" title="Tab panels &#8211; uitab and relatives">Tab panels &#8211; uitab and relatives </a> <small>This article describes several undocumented Matlab functions that support tab-panels...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-the-matlab-desktop-layout-programmatically" rel="bookmark" title="Setting the Matlab desktop layout programmatically">Setting the Matlab desktop layout programmatically </a> <small>The Matlab desktop enables saving and switching layouts using the main menu. This post shows how to do so programmatically....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/listbox-layout-customization" rel="bookmark" title="Listbox layout customization">Listbox layout customization </a> <small>Matlab's listbox layout can be modified to display multiple item columns and different inter-cell margins. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/common-javacomponent-problems" rel="bookmark" title="Common javacomponent problems">Common javacomponent problems </a> <small>The javacomponent function is very useful for placing Java components on-screen, but has a few quirks. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/matlab-layout-managers-uicontainer-and-relatives/feed</wfw:commentRss>
			<slash:comments>25</slash:comments>
		
		
			</item>
		<item>
		<title>GUIDE customization</title>
		<link>https://undocumentedmatlab.com/articles/guide-customization?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=guide-customization</link>
					<comments>https://undocumentedmatlab.com/articles/guide-customization#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 10 Jun 2009 17:00:43 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Hidden property]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[FindJObj]]></category>
		<category><![CDATA[GUIDE]]></category>
		<category><![CDATA[UIInspect]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=383</guid>

					<description><![CDATA[<p>Matlab's GUI Design Editor (GUIDE) has several interesting undocumented features. This post describes how to customize GUIDE rulers.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/guide-customization">GUIDE 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/button-customization" rel="bookmark" title="Button customization">Button customization </a> <small>Matlab's button uicontrols (pushbutton and togglebutton) are basically wrappers for a Java Swing JButton object. This post describes how the buttons can be customized using this Java object in ways that are impossible using pure Matlab....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-customization-report" rel="bookmark" title="Uitable customization report">Uitable customization report </a> <small>Matlab's uitable can be customized in many different ways. A detailed report explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/listbox-layout-customization" rel="bookmark" title="Listbox layout customization">Listbox layout customization </a> <small>Matlab's listbox layout can be modified to display multiple item columns and different inter-cell margins. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plotedit-context-menu-customization" rel="bookmark" title="PlotEdit context-menu customization">PlotEdit context-menu customization </a> <small>A combination of Matlab and Java Robot commands to automate a certain animation can be used when we cannot access underlying GUI/graphics code. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>GUIDE is the acronym for Matlab&#8217;s Graphical User Interface Design Editor. It is very handy for designing simple GUI figures, although my experience has shown that it has limitations for complex GUIs. Nevertheless, GUIDE is the tool used by most Matlab developers when designing GUIs. In this post, I will show a few undocumented customizations that could help make GUIDE sessions more productive.<br />
The starting point is GUIDE&#8217;s undocumented return value, which is a Java reference to the Layout Editor panel within the GUIDE figure frame:</p>
<blockquote>
<pre>
<span style="color: #000000;">&gt;&gt; h = guide</span>
h =
Layout Document [untitled]
<span style="color: #000000;">&gt;&gt; h.getClass</span>
ans =
class com.mathworks.toolbox.matlab.guide.LayoutEditor
</pre>
</blockquote>
<p>This return handle can be used to access GUIDE components and functionality. We can start by inspecting the interesting GUIDE layout hierarchy using my <a rel="nofollow" target="_blank" href="http://www.mathworks.com/matlabcentral/fileexchange/14317">FindJObj utility</a>, and the associated properties and method using my <a rel="nofollow" target="_blank" href="http://www.mathworks.com/matlabcentral/fileexchange/17935">UIInspect utility</a>:</p>
<blockquote>
<pre><span style="color: #000000;">&gt;&gt; h.findjobj;
&gt;&gt; h.uiinspect;
</span></pre>
</blockquote>
<p><center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Hierarchy of Layout Editor within the GUIDE frame" src="https://undocumentedmatlab.com/images/guide_ruler1.png" title="Hierarchy of Layout Editor within the GUIDE frame" width="450" height="351" /><figcaption class="wp-caption-text">Hierarchy of Layout Editor within the GUIDE frame</figcaption></figure></center><br />
Note: If you wish to see the hierarchy of the entire GUIDE figure frame, simply run FindJObj on the frame reference, by either of the two following methods (and similarly for UIInspect):</p>
<blockquote>
<pre><span style="color: #000000;">&gt;&gt; findjobj(h.getFrame);
&gt;&gt; findjobj(h.getTopLevelWindow);
</span></pre>
</blockquote>
<p>We see that the Layout Editor contains, in addition to the expected LayoutArea and two MWScrollbars, several objects that relate to a ruler. These rulers can be activated via the GUIDE menu (Tools / Grid and Rulers), or via the Matlab Command Prompt as described below:<br />
Looking at the ruler properties in FindJObj or UIInspect, we can see a settable boolean property called &#8220;RulerState&#8221;. If we turn it on we can see that a very handy pixels-ruler appears. Once we set this property, it remains in effect for every future GUIDE session:<br />
<center><figure style="width: 430px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Before: GUIDE with no rulers" src="https://undocumentedmatlab.com/images/guide_ruler2.png" title="Before: GUIDE with no rulers" width="430" height="286" /><figcaption class="wp-caption-text">Before: GUIDE with no rulers</figcaption></figure></center></p>
<blockquote>
<pre lang="matlab">
h.getComponent(0).getComponent(4).setRulerState(true);  % Horizontal
h.getComponent(0).getComponent(5).setRulerState(true);  % Vertical
</pre>
</blockquote>
<p>Note: RulerState actually controls a system preference (LayoutShowRulers, a boolean flag) that controls the visibility of both rulers, and persists across Matlab/GUIDE sessions.  To change the visibility of only a single ruler for this GUIDE session only, or on old Matlab versions (e.g. Matlab 7.1 aka R14 SP3) that do not have the &#8216;RulerState&#8217; property, use the hide()/show()/setVisible(flag) methods, or set the &#8216;Visible&#8217; property:</p>
<blockquote>
<pre lang="matlab">
% Equivalent ways to show horizontal ruler for this GUIDE session only
hRuler = h.getComponent(0).getComponent(4);  % =top horizontal ruler
set(hRuler, 'Visible','on');
hRuler.setVisible(true);  % or: hRuler.setVisible(1)
hRuler.show();
</pre>
</blockquote>
<p><center><figure style="width: 430px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="After: GUIDE with pixel rulers" src="https://undocumentedmatlab.com/images/guide_ruler3.png" title="After: GUIDE with pixel rulers" width="430" height="286" /><figcaption class="wp-caption-text">After: GUIDE with pixel rulers</figcaption></figure></center><br />
Using this method, we can customize the rulers &#8211; options which are unavailable using the standard GUIDE menu options: We can specify horizontal/vertical grid size, tick &#038; label interval and similar ruler properties. For example, let&#8217;s set a 5-pixel minor tick interval, 25-pixel major interval, labels every 50 pixels, starting offset of 40 pixels and a ruler size limited at 260 pixels:</p>
<blockquote>
<pre lang="matlab">
hRuler = h.getComponent(0).getComponent(4);  % =top horizontal ruler
set(hRuler, 'MinorInterval',5, 'MajorInterval',25);
set(hRuler, 'LabelInterval',50, 'LabelUnit',50);
set(hRuler, 'Margin',40, 'Length',260);
</pre>
</blockquote>
<p><center><figure style="width: 430px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="GUIDE with modified pixel rulers" src="https://undocumentedmatlab.com/images/guide_ruler4.png" title="GUIDE with modified pixel rulers" width="430" height="286" /><figcaption class="wp-caption-text">GUIDE with modified pixel rulers</figcaption></figure></center><br />
Note that the vertical ruler&#8217;s labels start (=LabelStart property) at the figure&#8217;s height, and have a <em>decreasing</em> LabelInterval of -50. This is done because Java coordinates start counting from the top-left corner <em>downward</em>, whereas Matlab counts from the bottom-left <em>upward</em>. In GUIDE, we naturally wish to display the Matlab coordinates, hence the transformation.<br />
Note: unfortunately, most of these properties do not have equivalent settable system properties that I could find. Here is a list of all the GUIDE-related system properties that I found:</p>
<ul>
<li><strong>LayoutShowRulers</strong> &#8211; boolean, controls display of both rulers</li>
<li><strong>LayoutShowGuides</strong> &#8211; boolean, controls display of blue guidelines</li>
<li><strong>LayoutShowGrid</strong> &#8211; boolean, controls display of gray gridlines</li>
<li><strong>LayoutGridWidth</strong> &#8211; integer, controls the size of the grid boxes</li>
<li><strong>LayoutSnapToGrid</strong> &#8211; boolean, controls snap-to-grid behavior</li>
<li><strong>LayoutActivate</strong> &#8211; boolean, controls ability to run (activate) unsaved figures without confirmation</li>
<li><strong>LayoutChangeDefaultCallback</strong> &#8211; boolean, ??? (I can see this preference in my matlab.prf file but I have no idea what it does or how it got there&#8230;)</li>
<li><strong>LayoutExport</strong> &#8211; boolean, controls ability to export unsaved figures without confirmation</li>
<li><strong>LayoutExtension</strong> &#8211; boolean, controls display of file extension in the GUIDE window title</li>
<li><strong>LayoutFullPath</strong> &#8211; boolean, controls display of file path in the GUIDE window title</li>
<li><strong>LayoutMCodeComments</strong> &#8211; boolean, controls generation of comments for m-file callbacks</li>
<li><strong>LayoutToolBar</strong> &#8211; boolean, controls display of the GUIDE widow toolbar</li>
<li><strong>LayoutToolNames</strong> &#8211; boolean, controls display of tool names in the components palette</li>
</ul>
<p>Have you discovered other undocumented features in GUIDE? If so, please share your findings in the comments section below.<br />
<strong><u>Warning</u></strong>: These undocumented features are way deep in unsupported territory. They depend heavily on Matlab&#8217;s internal implementation, which may change without any prior notice between Matlab releases. They work ok on Matlab versions 7.1 (R14 SP3) through 7.6 (R2008a), and perhaps on other versions as well. However, the very next Matlab release might break these features, so beware.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/guide-customization">GUIDE 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/button-customization" rel="bookmark" title="Button customization">Button customization </a> <small>Matlab's button uicontrols (pushbutton and togglebutton) are basically wrappers for a Java Swing JButton object. This post describes how the buttons can be customized using this Java object in ways that are impossible using pure Matlab....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/uitable-customization-report" rel="bookmark" title="Uitable customization report">Uitable customization report </a> <small>Matlab's uitable can be customized in many different ways. A detailed report explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/listbox-layout-customization" rel="bookmark" title="Listbox layout customization">Listbox layout customization </a> <small>Matlab's listbox layout can be modified to display multiple item columns and different inter-cell margins. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plotedit-context-menu-customization" rel="bookmark" title="PlotEdit context-menu customization">PlotEdit context-menu customization </a> <small>A combination of Matlab and Java Robot commands to automate a certain animation can be used when we cannot access underlying GUI/graphics code. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/guide-customization/feed</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
	</channel>
</rss>
