<?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>Guest bloggers &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/category/guest-bloggers/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Thu, 16 Jan 2025 15:33:04 +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 callbacks for uifigure JavaScript events</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlab-callbacks-for-uifigure-javascript-events</link>
					<comments>https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 15 Aug 2018 15:00:10 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Iliya Romm]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[uifigure]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7913</guid>

					<description><![CDATA[<p>Matlab callback code can be attached to JavaScript events in web-based uifigures. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events">Matlab callbacks for uifigure JavaScript events</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-callbacks-for-java-events" rel="bookmark" title="Matlab callbacks for Java events">Matlab callbacks for Java events </a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events-in-r2014a" rel="bookmark" title="Matlab callbacks for Java events in R2014a">Matlab callbacks for Java events in R2014a </a> <small>R2014a changed the way in which Java objects expose events as Matlab callbacks. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/detecting-window-focus-events" rel="bookmark" title="Detecting window focus events">Detecting window focus events </a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/enabling-user-callbacks-during-zoom-pan" rel="bookmark" title="Enabling user callbacks during zoom/pan">Enabling user callbacks during zoom/pan </a> <small>Matlab zoom, pan and rotate3d modes hijack the user's figure callbacks, but this can be overridden. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I would like to welcome back guest blogger Iliya Romm of Israel&#8217;s Technion <a href="http://bcukurel.net.technion.ac.il" rel="nofollow" target="_blank">Turbomachinery and Heat Transfer Laboratory</a>. Today Iliya will discuss how to assign Matlab callbacks to JavaScript events in the new web-based uifigures. Other posts on customizations of web-based Matlab GUI can be <a href="https://undocumentedmatlab.com/articles/tag/uifigure" target="_blank">found here</a>.</i><br />
On several occasions (including <a href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel" target="_blank">the previous post</a> by Khris Griffis) I came across people who were really missing the ability to have Matlab respond to various JavaScript (JS) events. While MathWorks are working on their plans to incorporate something similar to this in future releases, we&#8217;ll explore the internal tools already available, in the hopes of finding a suitable intermediate solution.<br />
Today I&#8217;d like to share a technique I&#8217;ve been experimenting with, allowing Matlab to respond to pretty much any JS event to which we can attach a listener. This is an overview of how it works:</p>
<ol>
<li>create a UIFigure with the desired contents, and add to it (at least) one more dummy control, which has an associated Matlab callback.</li>
<li>execute a JS snippet that programmatically interacts with the dummy control, whenever some event-of-interest happens, causing the Matlab callback to fire.</li>
<li>query the <code>webWindow</code>, from within the Matlab callback, to retrieve any additional information (“payload”) that the JS passed.</li>
</ol>
<p>This approach allows, for example, to easily respond to mouse events:<br />
<center><img decoding="async" src="https://undocumentedmatlab.com/images/XHDcA.gif" alt="Attaching Matlab callback to a uifigure JavaScript event" title="Attaching Matlab callback to a uifigure JavaScript event" width="80%" style="max-width:1135px;"/></center><br />
<span id="more-7913"></span><br />
Consider the code below, which demonstrates different ways of responding to JS events. To run it, save the <i>.m</i> file function below (<a href="/files/jsEventDemo.m" rel="nofollow" target="_blank">direct download link</a>) and the four accompanying <i>.js</i> <a href="#JS">files</a> in the same folder, then run <code>jsEventDemo(demoNum)</code>, where <code>demoNum</code> is 1..4. Note: this code was developed on R2018a, unfortunately I cannot guarantee it works on other releases.</p>
<pre lang="matlab">
function varargout = jsEventDemo(demoNum)
   % Handle inputs and outputs
   if ~nargin
      demoNum = 4;
   end
   if ~nargout
      varargout = {};
   end
   % Create a simple figure:
   hFig = uifigure('Position',[680,680,330,240],'Resize','off');
   hTA = uitextarea(hFig, 'Value', 'Psst... Come here...!','Editable','off');
   [hWin,idTA] = mlapptools.getWebElements(hTA);
   % Open in browser (DEBUG):
   % mlapptools.waitForFigureReady(hFig); mlapptools.unlockUIFig(hFig); pause(1);
   % web(hWin.URL,'-browser')
   % Prepare the JS command corresponding to the requested demo (1-4)
   switch demoNum
      % Demo #1: Respond to mouse events, inside JS, using "onSomething" bindings:
      case 1
         % Example from: https://dojotoolkit.org/documentation/tutorials/1.10/events/#dom-events
         jsCommand = sprintf(fileread('jsDemo1.js'), idTA.ID_val);
      % Demo #2: Respond to mouse click events, inside JS, using pub/sub:
      case 2
         % Example from: https://dojotoolkit.org/documentation/tutorials/1.10/events/#publish-subscribe
         hTA.Value = 'Click here and see what happens';
         jsCommand = sprintf(fileread('jsDemo2.js'), idTA.ID_val);
      % Demo #3: Trigger Matlab callbacks programmatically from JS by "pressing" a fake button:
      case 3
         hB = uibutton(hFig, 'Visible', 'off', 'Position', [0 0 0 0], ...
                       'ButtonPushedFcn', @fakeButtonCallback);
         [~,idB] = mlapptools.getWebElements(hB);
         jsCommand = sprintf(fileread('jsDemo3.js'), idTA.ID_val, idB.ID_val);
      % Demo 4: Trigger Matlab callbacks and include a "payload" (i.e. eventData) JSON:
      case 4
         hB = uibutton(hFig, 'Visible', 'off', 'Position', [0 0 0 0],...
                      'ButtonPushedFcn', @(varargin)smartFakeCallback(varargin{:}, hWin));
         [~,idB] = mlapptools.getWebElements(hB);
         jsCommand = sprintf(fileread('jsDemo4.js'), idTA.ID_val, idB.ID_val);
   end % switch
   % Execute the JS command
   hWin.executeJS(jsCommand);
end
% Matlab callback function used by Demo #3
function fakeButtonCallback(obj, eventData) %#ok<inusd>
   disp('Callback activated!');
   pause(2);
end
% Matlab callback function used by Demo #4
function smartFakeCallback(obj, eventData, hWin)
   % Retrieve and decode payload JSON:
   payload = jsondecode(hWin.executeJS('payload'));
   % Print payload summary to the command window:
   disp(['Responding to the fake ' eventData.EventName ...
         ' event with the payload: ' jsonencode(payload) '.']);
   % Update the TextArea
   switch char(payload.action)
      case 'enter',  act_txt = 'entered';
      case 'leave',  act_txt = 'left';
   end
   str = ["Mouse " + act_txt + ' from: '; ...
          "(" + payload.coord(1) + ',' + payload.coord(2) + ')'];
   obj.Parent.Children(2).Value = str;
end
</pre>
<p>Several thoughts:</p>
<ul>
<li>The attached <i>.js</i> files will not work by themselves, rather, they require <i><b>sprintf</b></i> to replace the <code>%s</code> with valid widget IDs. Of course, these could be made into proper JS functions.</li>
<li>Instead of loading the JS files using <i><b>fileread</b></i>, we could place the JS code directly in the <code>jsCommand</code> variable, as a Matlab string (char array)</li>
<li>I tried getting it to work with a <a href="https://www.w3schools.com/tags/tag_textarea.asp" rel="nofollow" target="_blank"><code>textarea</code> control</a>, so that we would get the payload right in the callback&#8217;s <code>eventData</code> object in Matlab, Unfortunately, I couldn&#8217;t get it to fire programmatically (solutions <a href="https://stackoverflow.com/a/36648958/3372061" rel="nofollow" target="_blank">like this</a> didn&#8217;t work). So instead, I store the payload as JSON, and retrieve it with <code>jsondecode(hWin.executeJS('payload'))</code> in the <code>smartFakeCallback</code> function.</li>
</ul>
<h3 id="JS">JavaScript files</h3>
<ol>
<li id="jsDemo1"><b>jsDemo1.js</b> (<a href="https://gist.github.com/Dev-iL/7bd222efb01b3bf9fc0ed5d5645d53e7/raw/872d3d7d00a7b2e18e87257e0ff7c2b6efaa4e45/jsDemo1.js" rel="nofollow" target="_blank">direct download link</a>):
<pre lang="javascript">
require(["dojo/on", "dojo/dom", "dojo/dom-style", "dojo/mouse"],
	function(on, dom, domStyle, mouse) {
		var myDiv = dom.byId("%s");
		on(myDiv, mouse.enter, function(evt){
			domStyle.set(myDiv, "backgroundColor", "red");
		});
		on(myDiv, mouse.leave, function(evt){
			domStyle.set(myDiv, "backgroundColor", "");
		});
	});
</pre>
</li>
<li id="jsDemo2"><b>jsDemo2.js</b> (<a href="https://gist.github.com/Dev-iL/7bd222efb01b3bf9fc0ed5d5645d53e7/raw/872d3d7d00a7b2e18e87257e0ff7c2b6efaa4e45/jsDemo2.js" rel="nofollow" target="_blank">direct download link</a>):
<pre lang="javascript">
require(["dojo/on", "dojo/topic", "dojo/dom"],
	function(on, topic, dom) {
		var myDiv = dom.byId("%s");
		on(myDiv, "click", function() {
			topic.publish("alertUser", "Your click was converted into an alert!");
		});
		topic.subscribe("alertUser", function(text){
			alert(text);
		});
	});
</pre>
</li>
<li id="jsDemo3"><b>jsDemo3.js</b> (<a href="https://gist.github.com/Dev-iL/7bd222efb01b3bf9fc0ed5d5645d53e7/raw/872d3d7d00a7b2e18e87257e0ff7c2b6efaa4e45/jsDemo3.js" rel="nofollow" target="_blank">direct download link</a>):
<pre lang="javascript">
require(["dojo/on", "dojo/dom", "dojo/dom-style", "dojo/mouse"],
	function(on, dom, domStyle, mouse) {
		var myDiv = dom.byId("%s");
		var fakeButton = dom.byId("%s");
		on(myDiv, mouse.enter, function(evt){
			fakeButton.click();
		});
	});
</pre>
</li>
<li id="jsDemo4"><b>jsDemo4.js</b> (<a href="https://gist.github.com/Dev-iL/7bd222efb01b3bf9fc0ed5d5645d53e7/raw/872d3d7d00a7b2e18e87257e0ff7c2b6efaa4e45/jsDemo4.js" rel="nofollow" target="_blank">direct download link</a>):
<pre lang="javascript">
var payload = [];
require(["dojo/on", "dojo/dom", "dojo/topic", "dojo/mouse"],
	function(on, dom, topic, mouse) {
		var myDiv = dom.byId("%s");
		var fakeButton = dom.byId("%s");
		topic.subscribe("sendToMatlab", function(data){
			payload = data;
			fakeButton.click();
		});
		on(myDiv, mouse.enter, function(evt){
			data = {action: "enter",
				coord: [evt.clientX, evt.clientY]};
			topic.publish("sendToMatlab", data);
		});
		on(myDiv, mouse.leave, function(evt){
			data = {action: "leave",
				coord: [evt.clientX, evt.clientY]};
			topic.publish("sendToMatlab", data);
		});
	});
</pre>
</li>
</ol>
<h3 id="Conclusions">Conclusions</h3>
<p>As you can see, this opens some interesting possibilities, and I encourage you to experiment with them yourself! This feature will likely be added to the <a href="https://github.com/StackOverflowMATLABchat/mlapptools" rel="nofollow" target="_blank"><code>mlapptools</code> toolbox</a> as soon as an intuitive API is conceived.<br />
If you have any comments or questions about the code above, or just want to tell me how you harnessed this mechanism to upgrade your uifigure (I would love to hear about it!), feel free to leave a message below <a href="https://gist.github.com/Dev-iL/7bd222efb01b3bf9fc0ed5d5645d53e7" rel="nofollow" target="_blank">the gist</a> on which this post is based (this way I get notifications!).</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events">Matlab callbacks for uifigure JavaScript events</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-callbacks-for-java-events" rel="bookmark" title="Matlab callbacks for Java events">Matlab callbacks for Java events </a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events-in-r2014a" rel="bookmark" title="Matlab callbacks for Java events in R2014a">Matlab callbacks for Java events in R2014a </a> <small>R2014a changed the way in which Java objects expose events as Matlab callbacks. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/detecting-window-focus-events" rel="bookmark" title="Detecting window focus events">Detecting window focus events </a> <small>Matlab does not have any documented method to detect window focus events (gain/loss). This article describes an undocumented way to detect such events....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/enabling-user-callbacks-during-zoom-pan" rel="bookmark" title="Enabling user callbacks during zoom/pan">Enabling user callbacks during zoom/pan </a> <small>Matlab zoom, pan and rotate3d modes hijack the user's figure callbacks, but this can be overridden. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Customizing web-GUI uipanel</title>
		<link>https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-web-gui-uipanel</link>
					<comments>https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 01 Aug 2018 18:00:13 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<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[Iliya Romm]]></category>
		<category><![CDATA[Khris Griffis]]></category>
		<category><![CDATA[uifigure]]></category>
		<category><![CDATA[uipanel]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7804</guid>

					<description><![CDATA[<p>We can customize Matlab's new web-based GUI  panels in many interesting ways. Here's how... </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel">Customizing web-GUI uipanel</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-3" rel="bookmark" title="Customizing uifigures part 3">Customizing uifigures part 3 </a> <small>As I have repeatedly posted in recent years, Matlab is advancing towards web-based GUI. The basic underlying technology is more-or-less stable: an HTML/Javascript webpage that is created-on-the-fly and rendered in a stripped-down browser window (based on Chromium-based jxBrowser in recent...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2" rel="bookmark" title="Customizing uifigures part 2">Customizing uifigures part 2 </a> <small>Matlab's new web-based uifigures can be customized using custom CSS and Javascript code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-matlab-uipanels" rel="bookmark" title="Customizing Matlab uipanels">Customizing Matlab uipanels </a> <small>Matlab uipanel controls can be customized using Java in ways that are impossible with plain Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-part-3-backdrop" rel="bookmark" title="Customizing axes part 3 &#8211; Backdrop">Customizing axes part 3 &#8211; Backdrop </a> <small>Matlab HG2 axes can be customized in many different ways. This article explains some of the undocumented aspects. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I would like to introduce guest blogger <a href="https://github.com/Khlick" rel="nofollow" target="_blank">Khris Griffis</a>. Today, Khris will continue the series of posts on <a href="https://undocumentedmatlab.com/articles/tag/uifigure" target="_blank">web-based uifigure customization</a> with an article showing how to create scrollable/customizable panels in web-based uifigures. This post follows <a href="https://undocumentedmatlab.com/articles/scrollable-gui-panels" target="_blank">last-week&#8217;s article</a>, about placing controls/axes within a scroll-panel in non-web (Java-based) figures. Users interested in advanced aspects and insights on the development roadmap of web-based Matlab GUI should also read <a href="https://blogs.mathworks.com/loren/2018/07/25/the-state-of-app-building-in-matlab" rel="nofollow" target="_blank">Loren Shure&#8217;s blog post from last week</a>.</i></p>
<h3 id="Motivation">Motivation</h3>
<p>As a retinal physiologist, I spend a lot of time in Matlab creating GUIs to visualize and analyze electrophysiological data. The data often requires a lot of processing and quality control checks before it can be used for interpretation and publication. Consequently, I end up with many control elements taking up precious space on my GUI.<br />
In Java-based (legacy/GUIDE) figures, this wasn&#8217;t a huge problem because, depending on what GUI components I needed, I could use a pure Matlab approach (a child panel within a parent panel, with a couple of control sliders moving the child panel around), or a number of Java approaches (which are always more fun; Yair <a href="https://undocumentedmatlab.com/articles/scrollable-gui-panels" target="_blank">described such an approach</a> last week).<br />
Unfortunately, the web-based (App-Designer) figure framework doesn&#8217;t support Java, and the pure/documented Matlab approach just doesn&#8217;t look good or function very well:<br />
<!--
If you're like me, you've once (or twice) queried your favorite search engine with "<i>Matlab scrolling uipanel</i>" and found 2 useful methods: a pure Matlab approach and <a href="https://undocumentedmatlab.com/articles/scrollable-gui-panels" target="_blank">a fun Java approach</a> (sticking objects in a <code>JScrollPane</code>, as explained in last week's post). Now, we read <i>Undocumented Matlab</i>, so we typically opt for the Java approach and our app is beautiful and the world is right... and countless hours of my life will go completely unnoticed by everyone using my app. But then the internet gets fast enough, servers get big enough, or for whatever reason, browser-/web-based apps are now <i>the</i> thing, so The Mathworks Inc. went and developed the <i><b>uifigure</b></i> to, you know, catch up.
The problem is, the new web framework eliminates our ability to use the Java approach and severely dampens the aesthetic of a pure Matlab approach (a child panel within a parent panel, with a couple of control sliders moving the child panel around). And that approach was already pretty ugly, if you care about that kind of stuff. So how can we make a scrolling <i><b>uipanel</b></i> to hold all these fancy, new <i><b><a href="https://www.mathworks.com/help/matlab/ref/uiknob.html" rel="nofollow" target="_blank">uiknob</a></b></i> controls?
--><br />
<center style="font-size:12px;"><img fetchpriority="high" decoding="async" src="https://undocumentedmatlab.com/images/uipanel_badscrolls.png" alt="AppDesigner uislider is not a good scrollbar, no matter what we do to it!" title="AppDesigner uislider is not a good scrollbar, no matter what we do to it!" width="473" height="187" /><br />
AppDesigner <i><b>uislider</b></i> is not a good scrollbar, no matter what we do to it!</center><br />
Fortunately, the new web framework allows us to use HTML, CSS and JavaScript (JS) to modify elements in the <i><b>uifigure</b></i>, i.e. its web-page <a href="https://en.wikipedia.org/wiki/Document_Object_Model" rel="nofollow" target="_blank">DOM</a>. It turns out that the <i><b>uipanel</b></i> object is essentially just a <code>&lt;div&gt;</code> with a Matlab-designed CSS style. We can customize it with little effort.<br />
The main goal here is to create a scrollable customizable <i><b>uipanel</b></i> containing many uicontrol elements, which could look something like this:<br />
<center style="font-size:12px;"><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_ADfig_1.png" alt="Running app demo" title="Running app demo" width="450" height="355" style="max-width:804px;"/></center><br />
<span id="more-7804"></span></p>
<h3 id="Example">A simple command-window example</h3>
<p>Since we are building on the series of <i><b>uifigure</b></i> customizations, I expect you have already read the preceding related <i>Undocumented Matlab</i> posts:</p>
<ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-1" target="_blank">Customizing uifigures part 1</a></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2" target="_blank">Customizing uifigures part 2</a></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-3" target="_blank">Customizing uifigures part 3</a></li>
</ol>
<p>Also, I <i>highly recommend</i> cloning (or at least downloading) the <a href="https://github.com/StackOverflowMATLABchat/mlapptools" rel="nofollow" target="_blank">mlapptools toolbox</a> repo on Github (thanks <a href="http://bcukurel.net.technion.ac.il" rel="nofollow" target="_blank">Iliya Romm</a> et al.). We will use it to simplify life today.<br />
<!--
Alright, let's say your GUI calls for a scroll-panel full of knobs, because who doesn't love having a plethora of knobs around?
<center><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_scrollApp.gif" alt="A scrollable panel can hide control widgets easily!" title="A scrollable panel can hide control widgets easily!" width="80%" style="max-width:822px;" /></center>
--><br />
Using the <code>mlapptools</code> toolbox, we need just a few lines of code to set up a scrollable panel. The important thing is knowing how big the panel needs to be to hold all of our control objects. Once we know this, we simply set the panel&#8217;s <b>Position</b> property accordingly. Then we can use simple CSS to display scrollbars and define the viewing dimensions.<br />
For example, if we need 260px in width by 720px in height to hold our control widgets, but only have 200px height available, we can solve this problem in 3 steps:</p>
<ol>
<li>Set the <i><b>uipanel</b></i>&#8216;s <b>Dimension</b> property to be 260px wide by 720px tall.</li>
<li>Set the viewing height using <code>mlapptools.setStyle(scrollPane,'height','200px')</code> for the panel&#8217;s CSS <code>height</code> style attribute.</li>
<li>Display the vertical scrollbar by calling <code>mlapptools.setStyle(scrollPane,'overflow-y','scroll')</code> for the panel&#8217;s CSS <code>overflow-y='scroll'</code> style attribute.</li>
</ol>
<pre lang="matlab">
% Create the figure
fig = uifigure('Name', 'Scroll Panel Test');
% Place a uipanel on the figure, color it for fun
scrollPane = uipanel(fig, 'BackgroundColor', [0.5,0.4,1]);
% Define the space requirements for the controls
totalWidth  = 260; %px
totalHeight = 720; %px
viewHeight  = 200; %px
% STEP 1: set the uipanel's Position property to the required dimensions
scrollPane.Position(3) = totalWidth;  % WIDTH
scrollPane.Position(4) = totalHeight; % HEIGHT
% STEP 2: set the viewing height
mlapptools.setStyle(scrollPane, 'height', sprintf('%dpx', viewHeight));
% STEP 3: display the vertical scrollbar
mlapptools.setStyle(scrollPane, 'overflow-y', 'scroll');
% Add control elements into the uipanel
...
</pre>
<p><center style="font-size:12px;"><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_exampleFig.png" alt="Example scrollable uipanel in a Matlab uifigure" title="Example scrollable uipanel in a Matlab uifigure" width="70%" style="max-width:450px;"/><!-- 619px --><br />
Example scrollable uipanel in a Matlab uifigure</center><br />
Because this is a web-based GUI, notice that you can simply hover your mouse over the panel and scroll with your scroll wheel. Awesome, right?<br />
Note that the CSS <code>height</code>/<code>width</code> style attributes don&#8217;t affect the actual size of our panel, just how much of the panel we can see at once (&#8220;viewport&#8221;).<br />
The CSS <code>overflow</code> style attribute has a number of options. For example, <code>setStyle(scrollPane,'overflow','auto')</code> causes scrollbars to automatically hide when the viewing area is larger than panel&#8217;s dimensions. Review the <a href="https://www.w3schools.com/css/css_overflow.asp" rel="nofollow" target="_blank">CSS <code>overflow</code> attribute</a> to learn about other related settings that affect the panel&#8217;s behavior.</p>
<h3 id="Scrollbars">Styling the scrollbars</h3>
<p>The <code>mlapptools</code> toolbox utilizes <i>dojo.js</i> to query the DOM and set styles, which is essentially setting inline styles on the DOM element, i.e. <code>&lt;div ... style="color: red;background:#FEFEFE;..."&gt; ... &lt;/div&gt;</code>. This has the added benefit of overriding any CSS classes Matlab is imposing on the DOM (see <a href="https://css-tricks.com/precedence-css-order-css-matters" rel="nofollow" target="_blank">CSS precedence</a>). We can inject our own classes into the page&#8217;s <code>&lt;head&gt;</code> tag and then use <code>dojo.setClass()</code> to apply our classes to specific GUI elements. For example, we can style our bland scrollbars by using CSS to define a custom <code>scrollpane</code> style class:</p>
<pre lang="css">
/* CSS To stylize the scrollbar */
.scrollpane::-webkit-scrollbar {
  width: 20px;
}
/* Track */
.scrollpane::-webkit-scrollbar-track {
  background-color: white;
  box-shadow: inset 0 0 5px white;
  border-radius: 10px;
}
/* Handle */
.scrollpane::-webkit-scrollbar-thumb {
  background: red;
  border-radius: 10px;
}
/* Handle on hover */
.scrollpane::-webkit-scrollbar-thumb:hover {
  background: #b30000;
}
</pre>
<p>To get the CSS into the document header, we need to first convert (&#8220;stringify&#8221;) it in Matlab:</p>
<pre lang="matlab">
% CSS styles 'stringified' for MATLAB
%  note that the whole style tag is wrapped in single quotes, that is required!
%  i.e. '<style>...</style>' which prints to the command window as:
%   ''<style>...</style>''
cssText = [...
  '''<style>\n', ...
  '  .scrollpane::-webkit-scrollbar {\n', ...
  '    width: 20px;\n', ...
  '  }\n', ...
  '  /* Track */\n', ...
  '  .scrollpane::-webkit-scrollbar-track {\n', ...
  '    background-color: white;\n', ...
  '    box-shadow: inset 0 0 5px white;\n', ...
  '    border-radius: 10px;\n', ...
  '  }\n', ...
  '  /* Handle */\n', ...
  '  .scrollpane::-webkit-scrollbar-thumb {\n', ...
  '    background: red; \n', ...
  '    border-radius: 10px;\n', ...
  '  }\n', ...
  '  /* Handle on hover */\n', ...
  '  .scrollpane::-webkit-scrollbar-thumb:hover {\n', ...
  '    background: #b30000; \n', ...
  '  }\n', ...
  '</style>''' ...
  ];
</pre>
<p>As explained in <a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-1" target="_blank">Customizing uifigures part 1</a>, we can execute JavaScript (JS) commands through the <code>webWindow</code> object. To simplify it, we use the method from <a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2" target="_blank">Customizing uifigures part 2</a> to obtain the <code>webWindow</code> object for our GUI window and and use the <code>executeJS()</code> method to add our HTML into the document&#8217;s <code>&lt;head&gt;</code> tag. It is worth checking out the properties and methods of <a href="https://www.w3schools.com/jsref/dom_obj_document.asp" rel="nofollow" target="_blank">the JS <code>document</code> object</a>.</p>
<pre lang="matlab">
% get the webWindow object
webWindow = mlapptools.getWebWindow(fig);
% inject the CSS
webWindow.executeJS(['document.head.innerHTML += ',cssText]);
</pre>
<p>Now the tricky part is that we have to assign our new CSS <code>scrollpane</code> class to our <i><b>uipanel</b></i>. We need 2 things: the <code>webWindow</code> object and the <code>data-tag</code> (our panel&#8217;s unique ID) attribute.</p>
<pre lang="matlab">
% get the uipanel data-tag attr.
[webWindow, panelID] = mlapptools.getWebElements(scrollPane);
%make a dojo.js statement (use addClass method)
setClassString = sprintf(...
  'dojo.addClass(dojo.query("[%s = ''%s'']")[0], "%s")',...
  panelID.ID_attr, panelID.ID_val, 'scrollpane');
% add class to DOM element
webWindow.executeJS(setClassString);
</pre>
<p><center style="font-size:12px;"><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_styledScroll.gif" alt="The results of applying our scrollpane CSS style on our scroll-pane's scrollbars" title="The results of applying our scrollpane CSS style on our scroll-pane's scrollbars" width="70%" style="max-width:450px;"/><!-- 566px --><br />
The results of applying our <code>scrollpane</code> CSS style on our scroll-pane&#8217;s scrollbars</center><br />
Note: Unfortunately, because of CSS precedence rules, we may have to use the dreaded <a href="https://www.smashingmagazine.com/2010/11/the-important-css-declaration-how-and-when-to-use-it" rel="nofollow" target="_blank"><code>!important</code> CSS qualifier</a> to get the desired effect. So if the result doesn&#8217;t match your expectations, try adding <code>!important</code> to the CSS class attributes.</p>
<h3 id="uipanel">Styling the <i>uipanel</i></h3>
<p>Each <i><b>uipanel</b></i> appears to be composed of 4 <code>&lt;div&gt;</code> HTML elements: a wrapper, internal container for the panel title, a separator, and the panel&#8217;s body (contents). We first use <code>mlapptools.getWebElements()</code> to get the <code>data-tag</code> ID for the wrapper node. We can then apply styles to the wrapper, or any child node, with CSS and JS.<br />
For example, we can use CSS3 patterns (such as one in <a href="http://lea.verou.me/css3patterns/#" rel="nofollow" target="_blank">this CSS3 gallery</a>) to liven up our panel. We can also use CSS to define a block element that will replace the title container with some static text. The CSS below would be appended to the <code>cssText</code> string we made for styling the scrollbars above:</p>
<pre lang="css">
/* DECORATE THE BACKGROUND */
/* Stars modified from: http://lea.verou.me/css3patterns/#stars */
.scrollpane {
  overflow: auto;
  background:
  linear-gradient(324deg, #232927 4%,   transparent 4%)   -70px 43px,
  linear-gradient( 36deg, #232927 4%,   transparent 4%)    30px 43px,
  linear-gradient( 72deg, #e3d7bf 8.5%, transparent 8.5%)  30px 43px,
  linear-gradient(288deg, #e3d7bf 8.5%, transparent 8.5%) -70px 43px,
  linear-gradient(216deg, #e3d7bf 7.5%, transparent 7.5%) -70px 23px,
  linear-gradient(144deg, #e3d7bf 7.5%, transparent 7.5%)  30px 23px,
  linear-gradient(324deg, #232927 4%,   transparent 4%)   -20px 93px,
  linear-gradient( 36deg, #232927 4%,   transparent 4%)    80px 93px,
  linear-gradient( 72deg, #e3d7bf 8.5%, transparent 8.5%)  80px 93px,
  linear-gradient(288deg, #e3d7bf 8.5%, transparent 8.5%) -20px 93px,
  linear-gradient(216deg, #e3d7bf 7.5%, transparent 7.5%) -20px 73px,
  linear-gradient(144deg, #e3d7bf 7.5%, transparent 7.5%)  80px 73px !important;
  background-color: #232977 !important;
  background-size: 100px 100px !important;
}
/* STYLES TO CENTER A TEXT BLOCK ON A WHITE SEMI-TRANSPARENT BACKGROUND BLOCK */
/* White block div */
.blockdiv {
  color: black;
  font: 25px Arial, sans-serif !important;
  background: rgba(255,255,255,0.75);
  width: 100%;
  height: 30px;
}
/* Text container centered in .blockdiv */
.textdiv {
  position: relative;
  float: left;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
</pre>
<p>To insert a static text element and its container, we can create a small JS routine that creates parent and child nodes that replace the panel&#8217;s title container:</p>
<pre lang="matlab">
% Make a nodeID string to make the JS call more generic
nodeID = sprintf('''[%s="%s"]''', panelID.ID_attr, panelID.ID_val);
% JS that creates a div within a div, each with their own classes
% The inner div gets the text and is centered within the outer div
% These elements are added before the node MATLAB will use for any controls
% added to scrollPane
js = sprintf( ...
  [ ...
    'var d = document.createElement("div");', ...
    'var t = document.createElement("div");', ...
    'd.classList.add("blockdiv");',...
    't.classList.add("textdiv");', ...
    't.innerHTML= "Some Static Text";', ...
    'd.appendChild(t);', ...
    'document.querySelectorAll(%s)[0]',...
    '.replaceChild(d,document.querySelectorAll(%s)[0].firstChild);' ...
  ], ...
  nodeID, nodeID ...
);
% execute the JS
webWindow.executeJS(js);
</pre>
<p><center style="font-size:12px;"><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_bgScroll.gif" alt="Panel background and static elements" title="Panel background and static elements" width="70%" style="max-width:450px;"/><!-- 566px --><br />
Panel background and static elements</center><br />
It seems to me that this approach might help to make lighter-weight apps, instead of having to make all those <i><b>app.Label</b></i> objects in Matlab&#8217;s App-Designer.</p>
<h3 id="Recap">Quick recap</h3>
<p>So let&#8217;s restate the process:</p>
<ol>
<li>Create a <i><b>uipanel</b></i> with the <b>Position</b> property set accordingly large enough for your control elements.</li>
<li>Use <code>mlapptools.setStyle()</code> to set the <a href="https://www.w3schools.com/css/css_overflow.asp" rel="nofollow" target="_blank"><code>overflow</code> style attribute</a> as desired.</li>
<li>Use <code>mlapptools.setStyle()</code> to set the <code>width</code> and/or <code>height</code> style attributes to the viewing size (this is how big the viewing area of the panel needs to be in order to fit nicely in your app).</li>
<li>Add your control elements with the scrolling <i><b>uipanel</b></i> as the parent.</li>
<li>If you want some special styles, create a stylesheet and inject it into the <code>&lt;head&gt;</code> and be sure to add the class to your panel&#8217;s HTML <code>classList</code>.</li>
</ol>
<p>The order of items 2-4 are not really important. You just need to ensure that the panel is large enough (via its <b>Position</b> property) to include all your elements/controls.<br />
I really hope that one day soon MathWorks will add CSS and JS hooks to <i><b>uifigure</b></i> GUI components (perhaps as settable <b>CSS</b>/<b>JS</b> properties that accept strings?), so that Matlab users could attach their own CSS and JS customizations directly within AppDesigner, without having to go through such undocumented hoops as I&#8217;ve shown here. In Loren Shure&#8217;s latest blog post, Matlab product manager <a href="https://blogs.mathworks.com/loren/2018/07/25/the-state-of-app-building-in-matlab/#573b536f-26bc-4a14-8d6b-38ed3c88b8d6" rel="nofollow" target="_blank">Dave Garisson indicated</a> that this is indeed planned for a near-future Matlab release (at least for JS, but hopefully also for CSS):</p>
<blockquote><p>&#8220;we are also investigating ways to provide a documented solution for integrating 3rd party JavaScript components in MATLAB apps.&#8221;</p></blockquote>
<h3 id="Example">A complete working example</h3>
<p>I created a complete working example in Matlab&#8217;s App Designer while figuring this whole thing out. The code (<i>CWE.m</i>) can be <a href="https://github.com/Khlick/matlabUiHacks/blob/master/scrollingUIPanel/CWE.m" rel="nofollow" target="_blank">downloaded here</a>, and then run directly from Matlab&#8217;s command window. Alternatively, the corresponding App Designer file (<i>CWE.mlapp</i>) can be <a href="https://github.com/Khlick/matlabUiHacks/blob/master/scrollingUIPanel/CWE.mlapp" rel="nofollow" target="_blank">downloaded here</a>. You are welcome to use/adapt the code in your own project. Just to be clear, I love wild colors and crazy themes, but I don&#8217;t recommend going this overboard for a real project.<br />
<center style="font-size:12px;"><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_ADfig_1.png" alt="Running app demo" title="Running app demo" width="80%" style="max-width:804px;"/><br />
Running app demo</center><br />
<!--


<h3 id="hijack">Hijacking the uipanel altogether</h3>


In the previous example, we replaced the <code>&lt;div&gt;</code> container for the title part of the <i><b>uipanel</b></i>. We can insert other types of DOM nodes into the <i><b>uipanel</b></i> as well, for example a JS-generated table.
Every <i><b>uifigure</b></i> is essentially a web page running within a browser. Using JS, we can query the <a href="https://www.w3schools.com/js/js_window_navigator.asp" rel="nofollow" target="_blank"><code>navigator</code> object</a>, which contains a lot of information on the browser (<a href="http://help.dottoro.com/ljcsokrr.php" rel="nofollow" target="_blank">see here</a>). These <code>navigator</code> properties can be displayed in a JS-generated table within a Matlab <i><b>uipanel</b></i> (<a href="https://undocumentedmatlab.com/files/browserInfo.m" target="_blank">downloadable source code</a>):
<center style="font-size:12px;"><img decoding="async" src="https://undocumentedmatlab.com/images/uipanel_matlabBrowserInfo.gif" alt="HTML table built with JS from the navigator object" title="HTML table built with JS from the navigator object" width="80%" style="max-width:700px;"/>
HTML table built with JS from the navigator object</center>
Note that these <code>navigator</code> properties correspond to my specific Matlab R2018a installation:


<pre lang="matlab">
>> version %MATLAB
    '9.4.0.813654 (R2018a)'
>> mlapptools.aboutJSLibs()  % display the loaded JS
  struct with fields:
        dojo: '1.11.2.91fa0cb'
    react_js: '0.14.7'
</pre>


--><br />
I can&#8217;t thank Yair enough for suggesting that I turn this tip into a guest post for you readers. And I want to give a huge thank you to you, the reader, for persevering all the way to the end of this post&#8230;<br />
Cheers!<br />
-Khris<br />
<b><u>Addendum September 17, 2018</u></b>: Scrolling panels in uifigures are now a fully-supported documented functionality via the new <a href="https://www.mathworks.com/help/matlab/ref/matlab.ui.container.tree.scroll.html" rel="nofollow" target="_blank"><i><b>scroll</b></i></a> function and <a href="https://www.mathworks.com/help/matlab/ref/matlab.ui.figureappd-properties.html#propname_Scrollable" rel="nofollow" target="_blank"><b>Scrollable</b></a> property, starting with Matlab release R2018b. You can still use the mechanism described above, which also works for older Matlab releases.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel">Customizing web-GUI uipanel</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-3" rel="bookmark" title="Customizing uifigures part 3">Customizing uifigures part 3 </a> <small>As I have repeatedly posted in recent years, Matlab is advancing towards web-based GUI. The basic underlying technology is more-or-less stable: an HTML/Javascript webpage that is created-on-the-fly and rendered in a stripped-down browser window (based on Chromium-based jxBrowser in recent...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2" rel="bookmark" title="Customizing uifigures part 2">Customizing uifigures part 2 </a> <small>Matlab's new web-based uifigures can be customized using custom CSS and Javascript code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-matlab-uipanels" rel="bookmark" title="Customizing Matlab uipanels">Customizing Matlab uipanels </a> <small>Matlab uipanel controls can be customized using Java in ways that are impossible with plain Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-axes-part-3-backdrop" rel="bookmark" title="Customizing axes part 3 &#8211; Backdrop">Customizing axes part 3 &#8211; Backdrop </a> <small>Matlab HG2 axes can be customized in many different ways. This article explains some of the undocumented aspects. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Spicing up the Matlab Editor</title>
		<link>https://undocumentedmatlab.com/articles/spicing-up-the-matlab-editor?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=spicing-up-the-matlab-editor</link>
					<comments>https://undocumentedmatlab.com/articles/spicing-up-the-matlab-editor#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 29 Mar 2018 21:34:20 +0000</pubDate>
				<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Andreas Justin]]></category>
		<category><![CDATA[Editor]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7472</guid>

					<description><![CDATA[<p>Matlab's Editor and Workspace can be enhanced quite significantly using an open-source utility. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/spicing-up-the-matlab-editor">Spicing up the Matlab Editor</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/editormacro-assign-a-keyboard-macro-in-the-matlab-editor" rel="bookmark" title="EditorMacro &#8211; assign a keyboard macro in the Matlab editor">EditorMacro &#8211; assign a keyboard macro in the Matlab editor </a> <small>EditorMacro is a new utility that enables setting keyboard macros in the Matlab editor. this post details its inner workings....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-the-matlab-editor" rel="bookmark" title="Accessing the Matlab Editor">Accessing the Matlab Editor </a> <small>The Matlab Editor can be accessed programmatically, for a wide variety of possible uses - this article shows how....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/non-textual-editor-actions" rel="bookmark" title="Non-textual editor actions">Non-textual editor actions </a> <small>The UIINSPECT utility can be used to expand EditorMacro capabilities to non-text-insertion actions. This is how:...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/recovering-previous-editor-state" rel="bookmark" title="Recovering previous editor state">Recovering previous editor state </a> <small>Recovering the previous state of the Matlab editor and its loaded documents is possible using a built-in backup config file. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I&#8217;d like to introduce guest blogger <a href="https://github.com/GavriYashar" rel="nofollow" target="_blank">Andreas Justin</a>, who will discuss some way-cool features in his Editor Plugin utility. Many of his feature implementations are not Editor-specific and can be reused in other Matlab-Desktop applications, for example dockable panels, and integration with Matlab&#8217;s main Preferences window.</i><br />
<i><b><u>Note</u>: I will be traveling to the USA in June, and to Spain in August. If you would like me to visit your location for onsite consulting or training, then please let me know.</b></i><br />
<i>Happy Easter/Passover!</i></p>
<h3 id="overview">Overview</h3>
<p><figure style="width: 128px" class="wp-caption alignright"><img decoding="async" src="https://undocumentedmatlab.com/images/Editor-plugin3.gif" alt="Editor-plugin's cool logo" title="Editor-plugin's cool logo" width="128" height="128" /><figcaption class="wp-caption-text">Editor-plugin's cool logo</figcaption></figure>Compared to other IDE like IntellIJ, Eclipse and many more, Matlab&#8217;s editor seems somewhat outdated. Especially writing Object-Oriented code in Matlab is kind of a hassle. To make Matlab more user friendly, I&#8217;ve written a Java app that adds important features to the editor &#8211; Features such as navigating inside Class-code and in Inherited members; Searching through methods and instantly jumping to desired location; Reopening an editor that was closed by accident; Storing bookmarks between Matlab sessions; and Live Templates using commands directly written in the editor, replaced by pre-defined text.</p>
<p>The default Keyboard shortcuts listed below for the features can be customized. Most variables can be customized as well (I will point out which variables are not [yet] customizable).<br />
Most GUIs have a search field. Within this search field you can move the list or the tree up and down using arrow keys, or hit &lt;escape&gt; to return to editor. These search fields allow you to enter regular expressions to limit results shown in list or tree. Also, most GUIs are dockable.<br />
The Editor-Plugin utility is open-source. It is available <a href="https://github.com/GavriYashar/Matlab-Editor-Plugin" rel="nofollow" target="_blank">on GitHub</a> and also mirrored <a href="https://www.mathworks.com/matlabcentral/fileexchange/58497-gavriyashar-matlab-editor-plugin" rel="nofollow" target="_blank">on the Matlab File Exchange</a>. A <a href="https://github.com/GavriYashar/Matlab-Editor-Plugin/wiki/Setup" rel="nofollow" target="_blank">detailed setup guide</a> is provided on the utility&#8217;s <a href="https://github.com/GavriYashar/Matlab-Editor-Plugin/wiki" rel="nofollow" target="_blank">wiki section in GitHub</a>.<br />
If you discover any problem or have any suggestion for improvement, please visit the utility&#8217;s <a href="https://github.com/GavriYashar/Matlab-Editor-Plugin/issues" rel="nofollow" target="_blank">Issues section on GitHub</a>, where all open/closed issues can be tracked and discussed.<br />
A brief overview of some of the features is presented below. For a detailed explanation of these and other features (which are not listed below), please review the <a href="https://github.com/GavriYashar/Matlab-Editor-Plugin/wiki/Features" rel="nofollow" target="_blank">Features section</a> of the utility&#8217;s wiki (you guessed it: on GitHub&#8230;).</p>
<style type="text/css" media="screen">
kbd {
    display: inline-block;
    padding: 3px 5px;
    font-size: 11px;
    line-height: 10px;
    color: #444d56;
    vertical-align: middle;
    background-color: #fafbfc;
    border: solid 1px #c6cbd1;
    border-bottom-color: #959da5;
    border-radius: 3px;
    box-shadow: inset 0 -1px 0 #959da5;
}
</style>
<h3 id="editing">Editing</h3>
<ul>
<li><b>Delete / duplicate lines</b> &#8211; <kbd>CTRL</kbd> + <kbd>SHIFT</kbd> + <kbd>Y</kbd> or <kbd>D</kbd> allows you to delete or duplicate current line.<br />
<center style="margin:7px;"><img decoding="async" src="https://undocumentedmatlab.com/images/Editor-plugin1.gif" alt="Deleting/duplicating complete lines" title="Deleting/duplicating complete lines" width="90%" style="max-width:778px;"/></center></li>
<li><b>Move lines up or down</b> &#8211; <kbd>CTRL</kbd> + <kbd>ALT</kbd> + <kbd>UP</kbd> or <kbd>DOWN</kbd> allows you to move selected lines up or down.<br />
<center style="margin:7px;"><img decoding="async" src="https://undocumentedmatlab.com/images/Editor-plugin10.gif" alt="Moving complete lines" title="Moving complete lines" width="90%" style="max-width:750px;"/></center></li>
<li><b>Live (auto-replace) templates</b> &#8211; Live Templates are editor commands you can design to insert predefined code. Here&#8217;s an example for the command <code>%this%</code> (delivered within the package). When you type a command into the editor the string will get replaced by the predefined text. This predefined text may include variables depending on what you want to achieve. <code>%this%</code> was designed to insert the fully qualified name of the current class you&#8217;re in (or function, or script).<br />
<center style="margin:7px;"><img decoding="async" src="https://undocumentedmatlab.com/images/Editor-plugin9.gif" alt="Auto-replace template" title="Auto-replace templates" width="90%" style="max-width:647px;"/></center></li>
<li><b>Clipboard Stack</b> &#8211; <kbd>CTRL</kbd> + <kbd>SHIFT</kbd> + <kbd>V</kbd> opens the Clipboard Stack, where the last 10 copied/cut text are stored and can be directly inserted into the current editor position. The Clipboard Stack only stores text copied from editor.</li>
</ul>
<p><span id="more-7472"></span></p>
<h3 id="navigation">Navigation</h3>
<ul>
<li><b>Auto switch current folder and detail viewer</b> &#8211; Switching editor tabs will update the Desktop&#8217;s current folder and detail viewer. This behavior can be directly changed in the detail viewer bar.<br />
Use the new icons in the Desktop&#8217;s Current Folder panel: <img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/Editor-plugin8.png" alt="Toggle detail viewer" title="Toggle detail viewer" width="16" height="16"/> to toggle detail viewer and <img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/Editor-plugin2.png" alt="Toggle following the current editor file" title="Toggle following the current editor file" width="16" height="16"/> to toggle following the current editor file.<br />
<center style="margin:7px;"><img decoding="async" src="https://undocumentedmatlab.com/images/Editor-plugin6.gif" alt="Follow current editor file" title="Follow current editor file" width="90%" style="max-width:574px;"/></center></li>
<li><b>File Structure</b> &#8211; I personally use this one the most: <kbd>CTRL</kbd> + <kbd>F12</kbd> will show a GUI that let you search methods and properties including inherited ones.<br />
<center style="margin:7px;"><img decoding="async" src="https://undocumentedmatlab.com/images/Editor-plugin7.gif" alt="File structure analysis" title="File structure analysis" width="90%" style="max-width:803px;"/></center></li>
<li><b>Navigation History</b> &#8211; Every editor file that is opened is stored in the navigation history. Up to 50 editor file paths are stored. If you have a 5-Button Mouse, you can navigate through previous location (backward and forward).</li>
<li><b>Recently Closed</b> &#8211; <kbd>CTRL</kbd> + <kbd>SHIFT</kbd> + <kbd>T</kbd> will show a GUI that allows you to reopen closed editors this or last session.</li>
<li><b>Bookmarks</b> &#8211; <kbd>CTRL</kbd> + <kbd>SHIFT</kbd> + <kbd>F2</kbd> will show a GUI that allows you to name, search and delete bookmarks. Matlab has this nice feature to delete bookmarks after closing the editor. This feature will store all bookmarks. If an editor or Matlab is closed and opened later. All Bookmarks will be restored.<br />
This feature has some issues though. The most obvious first: if the source file has been changed outside of Matlab, the bookmark does not get updated, and may point to the wrong line, or gets deleted. Also on some Systems the default shortcut does not work. But there are workarounds.</li>
</ul>
<h3 id="others">Other useful features</h3>
<ul>
<li><b>Dockable Windows</b> &#8211; As mentioned before, most GUIs are dockable.<br />
<center style="margin:7px;"><img decoding="async" src="https://undocumentedmatlab.com/images/Editor-plugin5.gif" alt="Dockable Windows" title="Dockable Windows" width="90%" style="max-width:820px;"/></center></li>
<li><b>Preferences</b> &#8211; Preferences panel integrated in Matlab&#8217;s main Preferences window.<br />
<center style="margin:7px;"><img decoding="async" src="https://undocumentedmatlab.com/images/Editor-plugin-preferences.png" alt="Preferences panel integrated in Matlab's main Preferences window" title="Preferences panel integrated in Matlab's main Preferences window" width="90%" style="max-width:912px;"/></center></li>
<li><b>Execute current line</b> &#8211; <kbd>SHIFT</kbd> + <kbd>F9</kbd> allows you to execute the current line. This is equivalent to selecting the entire line, then clicking <kbd>F9</kbd>, and is similar in concept to the editor&#8217;s built-in ability to execute the current cell-block.<br />
<center style="margin:7px;"><img decoding="async" src="https://undocumentedmatlab.com/images/Editor-plugin4.gif" alt="Execute current line" title="Execute current line" width="90%" style="max-width:795px;"/></center></li>
<li><b>VarDiff</b> &#8211; Select two variables in the workspace and compare them using Matlab&#8217;s internal comparison feature (adding a custom hook to the Workspace context-menu was <a href="/articles/customizing-workspace-context-menu" target="_blank">discussed by Yair</a> back in 2010).<br />
<center style="margin:7px;"><img decoding="async" src="https://undocumentedmatlab.com/images/Editor-plugin-Vardiff_context.png" alt="Variables comparison integrated in the Workspace browser" title="Variables comparison integrated in the Workspace browser" width="90%" style="max-width:392px;"/></center></li>
<li><b>KeyPressListener</b> &#8211; Allows you to create custom keyboard shortcuts for your own functions. A similar functionality was <a href="/articles/editormacro-assign-a-keyboard-macro-in-the-matlab-editor" target="_blank">discussed by Yair</a> back in 2009.</li>
</ul>
<p>As noted above, a detailed explanation of these and other features is provided in the <a href="https://github.com/GavriYashar/Matlab-Editor-Plugin/wiki/Features" rel="nofollow" target="_blank">Features section</a> of the utility&#8217;s wiki. If you discover any problem or have any suggestion for improvement, please visit the utility&#8217;s <a href="https://github.com/GavriYashar/Matlab-Editor-Plugin/issues" rel="nofollow" target="_blank">Issues section on GitHub</a>, where issues can be tracked and discussed.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/spicing-up-the-matlab-editor">Spicing up the Matlab Editor</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/editormacro-assign-a-keyboard-macro-in-the-matlab-editor" rel="bookmark" title="EditorMacro &#8211; assign a keyboard macro in the Matlab editor">EditorMacro &#8211; assign a keyboard macro in the Matlab editor </a> <small>EditorMacro is a new utility that enables setting keyboard macros in the Matlab editor. this post details its inner workings....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-the-matlab-editor" rel="bookmark" title="Accessing the Matlab Editor">Accessing the Matlab Editor </a> <small>The Matlab Editor can be accessed programmatically, for a wide variety of possible uses - this article shows how....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/non-textual-editor-actions" rel="bookmark" title="Non-textual editor actions">Non-textual editor actions </a> <small>The UIINSPECT utility can be used to expand EditorMacro capabilities to non-text-insertion actions. This is how:...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/recovering-previous-editor-state" rel="bookmark" title="Recovering previous editor state">Recovering previous editor state </a> <small>Recovering the previous state of the Matlab editor and its loaded documents is possible using a built-in backup config file. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/spicing-up-the-matlab-editor/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Matlab compilation quirks &#8211; take 2</title>
		<link>https://undocumentedmatlab.com/articles/matlab-compilation-quirks-take-2?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlab-compilation-quirks-take-2</link>
					<comments>https://undocumentedmatlab.com/articles/matlab-compilation-quirks-take-2#respond</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 31 May 2017 18:00:42 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Toolbox]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Compiler]]></category>
		<category><![CDATA[Hanan Kavitz]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6919</guid>

					<description><![CDATA[<p>A few hard-to-trace quirks with Matlab compiler outputs are explained. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-compilation-quirks-take-2">Matlab compilation quirks &#8211; take 2</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/quirks-with-compiled-matlab-dlls" rel="bookmark" title="Quirks with compiled Matlab DLLs">Quirks with compiled Matlab DLLs </a> <small>Several quirks with Matlab-compiled DLLs are discussed and workarounds suggested. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/quirks-with-parfor-vs-for" rel="bookmark" title="Quirks with parfor vs. for">Quirks with parfor vs. for </a> <small>Parallelizing loops with Matlab's parfor might generate unexpected results. Users beware! ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/secure-ssl-connection-between-matlab-and-postgresql" rel="bookmark" title="Secure SSL connection between Matlab and PostgreSQL">Secure SSL connection between Matlab and PostgreSQL </a> <small>It is tricky, but quite possible, to use SSL to connect Matlab to a PostgreSQL database. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-infiniband-with-matlab-parallel-computing-toolbox" rel="bookmark" title="Using Infiniband with Matlab Parallel Computing Toolbox">Using Infiniband with Matlab Parallel Computing Toolbox </a> <small>Infiniband networking can significantly improve PCT performance in Matlab parallelization and distributed computing. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>Once again I would like to welcome guest blogger <a href="https://www.mathworks.com/matlabcentral/profile/authors/2392999-hanan-kavitz" rel="nofollow" target="_blank">Hanan Kavitz</a> of <a href="http://www.appliedmaterials.com" rel="nofollow" target="_blank">Applied Materials</a>. Hanan posted a couple of guest posts here over the past few years, including a post last year about <a href="/articles/quirks-with-compiled-matlab-dlls" target="_blank">quirks with Matlab-compiled DLLs</a>. Today Hanan will follow up on that post by discussing several additional quirks that they have encountered with Matlab compilations/deployment.</i></p>
<h3 id="make"><i>Don&#8217;t fix it, if it ain&#8217;t broke&#8230;</i></h3>
<p>In Applied Materials Israel (PDC) we use Matlab code for both algorithm development and deployment (production). As part of the dev-ops build system, which builds our product software versions, we build Matlab artifacts (binaries) from the Matlab source code.<br />
A typical software version has several hundreds Matlab artifacts that are automatically rebuilt on a daily basis, and we have many such versions – totaling many thousands of compilations each day.<br />
This process takes a long time, so we were looking for a way to make it more efficient.<br />
The idea that we chose to implement sounds simple – take a single binary module in any software version (Ex. foo.exe &#8211; Matlab-compiled exe) and check it: if the source code for this module has not changed since the last compilation then simply <b>don&#8217;t compile it</b>, just copy it from previous software version repository. Since most of our code doesn&#8217;t change daily (some of it hasn&#8217;t changed in years), we can skip the compilation time of most binaries and just copy them from some repository of previously compiled binaries.<br />
<span id="more-6919"></span><br />
In a broader look, avoiding lengthy compilations cycles by not compiling unchanged code is a common programming practice, implemented by all modern compilers. For example, the ‘make’ utility uses a ‘makefile’ to check the time stamps of all dependencies of every object file in order to decide which object requires recompilation. In reality, this is not always the best solution as time stamps may be incorrect, but it works well in the vast majority of cases.<br />
Coming back to Matlab, now comes the hard part – how could our build system know that nothing has changed in module X and that something has changed in module Y? How does it even know which source files it needs to ensure didn&#8217;t change?<br />
The credit for the idea goes to my manager, Lior Cohen, as follows: You can actually check the dependency of a given binary after compilation. <b>The basis of the solution is that a Matlab executable is in fact a compressed (zip) file</b>. The idea is then to:</p>
<ol>
<li>Compile the binary once</li>
<li>Unzip the binary and “see” all your dependencies (source files are encrypted and resources are not, but we only need the list of file names – not their content).</li>
<li>Now build a list of all your dependency files and compute the CRC value of each from the source control. Save it for the next time you are required to compile this module.</li>
<li>In the next compilation cycle, find this dependency list, review it, dependency source file at a time and make sure CRC of the dependency hasn’t changed since last time.</li>
<li>If no dependency CRC has changed, then copy the binary from the repository of previous software version, without compiling.</li>
<li>Otherwise, recompile the binary and rebuild the CRC list of all dependencies again, in preparation for the next compilation cycle.</li>
</ol>
<p>That&#8217;s it! That simple? Well&#8230; not really – the reality is a bit more complex since there are many other dependencies that need to be checked. Some of them are:</p>
<ol>
<li>Did the requested Matlab version of the binary change since the last compilation?</li>
<li>Did the compilation instructions themselves (we have a sort of ‘makefile’) change?</li>
</ol>
<p>Basically, I implemented a policy that if anything changed, or if the dependency check itself failed, then we don&#8217;t take any chances and just compile this binary. Keeping in mind that this dependencies check and file copying is much faster than a Matlab compilation, we save a lot of actual compilation time using this method.<br />
<b>Bottom line</b>: Given a software version containing hundreds of compilation instructions to execute and assuming not much has changed in the version (which is often the case), we skip over 90% of compilations altogether and only rebuild what really changed. The result is a version build that takes about half an hour, instead of many hours. Moreover, since the compilation process is working significantly less, we get fewer failures, fewer stuck or crashed mcc processes, and [not less importantly] less maintenance required by me.<br />
Note that in our implementation we rely on the undocumented fact that Matlab binaries are in fact compressed zip archives. If and when a future Matlab release will change the implementation such that the binaries will no longer be zip archives, another way will need to be devised in order to ensure the consistency of the target executable with its dependent source files.</p>
<h3 id="antivirus"><i>Don&#8217;t kill it, if it ain&#8217;t bad&#8230;</i></h3>
<p>I want to share a very weird issue I investigated over a year ago when using Matlab compiled exe. It started with a user showed me a Matlab compiled exe that didn&#8217;t run &#8211; I&#8217;m not talking about a regular Matlab exception: the process was crashing with an MS Windows popup window popping, stating something very obscure.<br />
It was a very weird behavior that I couldn&#8217;t explain – the compiler seemed to work well but the compiled executable process kept crashing. Compiling completely different code showed the same behavior.<br />
This issue has to do with the system compiler configuration that is being used. As you might know, when installing the Matlab compiler, before the first compilation is ever made, the user has to state the C compiler that the Matlab compiler should use in its compilation process. This is done by command ‘mbuild –setup’. This command asks the users to choose the C compiler and saves the configuration (batch file back then, xml in the newer versions of Matlab) in the user&#8217;s <i><b>prefdir</b></i> folder. At the time we were using Microsoft Visual C++ compiler 9.0 SP1.<br />
The breakthrough in the investigation came when I ran mcc command with <code>–verbose</code> flag, which outputs much more compilation info than I would typically ever want&#8230; I discovered that although the target executable file had been created, a post compilation step failed to execute, while issuing a very cryptic error message:</p>
<blockquote><p>mt.exe : general error c101008d: Failed to write the updated manifest to the resource of file &#8220;&#8230;&#8221;. Access is denied.</p></blockquote>
<p><center><figure style="width: 450px" class="wp-caption aligncenter"><a href="/images/deployment_error.png" target="_blank"><img loading="lazy" decoding="async" alt="cryptic compilation error (click to zoom)" src="https://undocumentedmatlab.com/images/deployment_error.png" title="cryptic compilation error (click to zoom)" width="450" height="65" /></a><figcaption class="wp-caption-text">cryptic compilation error (click to zoom)</figcaption></figure></center><br />
The failure was in one of the ‘post link’ commands in the configuration batch file – something obscure such as this:</p>
<pre lang="bat">set POSTLINK_CMDS2=mt.exe -outputresource: %MBUILD_OUTPUT_FILE_NAME%;%MANIFEST_RESOURCE% -manifest "%MANIFEST_FILE_NAME%"</pre>
<p>This line of code takes an XML manifest file and inserts it into the generated binary file (<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa375649(v=vs.85).aspx" rel="nofollow" target="_blank">additional details</a>).<br />
If you open a valid R2010a (and probably other old versions as well) Matlab-generated exe in a text editor you can actually see a small XML code embedded in it, while in a non-functioning exe I could not see this XML code.<br />
So why would this command fail?<br />
It turned out, as funny as it sounds, to be an antivirus issue – our IT department updated its antivirus policies and this ‘post link’ command suddenly became an illegal operation. Once our IT eased the policy, this command worked well again and the compiled executables stopped crashing, to our great joy.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-compilation-quirks-take-2">Matlab compilation quirks &#8211; take 2</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/quirks-with-compiled-matlab-dlls" rel="bookmark" title="Quirks with compiled Matlab DLLs">Quirks with compiled Matlab DLLs </a> <small>Several quirks with Matlab-compiled DLLs are discussed and workarounds suggested. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/quirks-with-parfor-vs-for" rel="bookmark" title="Quirks with parfor vs. for">Quirks with parfor vs. for </a> <small>Parallelizing loops with Matlab's parfor might generate unexpected results. Users beware! ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/secure-ssl-connection-between-matlab-and-postgresql" rel="bookmark" title="Secure SSL connection between Matlab and PostgreSQL">Secure SSL connection between Matlab and PostgreSQL </a> <small>It is tricky, but quite possible, to use SSL to connect Matlab to a PostgreSQL database. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-infiniband-with-matlab-parallel-computing-toolbox" rel="bookmark" title="Using Infiniband with Matlab Parallel Computing Toolbox">Using Infiniband with Matlab Parallel Computing Toolbox </a> <small>Infiniband networking can significantly improve PCT performance in Matlab parallelization and distributed computing. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/matlab-compilation-quirks-take-2/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Quirks with parfor vs. for</title>
		<link>https://undocumentedmatlab.com/articles/quirks-with-parfor-vs-for?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=quirks-with-parfor-vs-for</link>
					<comments>https://undocumentedmatlab.com/articles/quirks-with-parfor-vs-for#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 05 Jan 2017 17:15:48 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6821</guid>

					<description><![CDATA[<p>Parallelizing loops with Matlab's parfor might generate unexpected results. Users beware! </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/quirks-with-parfor-vs-for">Quirks with parfor vs. for</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/a-few-parfor-tips" rel="bookmark" title="A few parfor tips">A few parfor tips </a> <small>The parfor (parallel for) loops can be made faster using a few simple tips. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-compilation-quirks-take-2" rel="bookmark" title="Matlab compilation quirks &#8211; take 2">Matlab compilation quirks &#8211; take 2 </a> <small>A few hard-to-trace quirks with Matlab compiler outputs are explained. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/quirks-with-compiled-matlab-dlls" rel="bookmark" title="Quirks with compiled Matlab DLLs">Quirks with compiled Matlab DLLs </a> <small>Several quirks with Matlab-compiled DLLs are discussed and workarounds suggested. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/preallocation-performance" rel="bookmark" title="Preallocation performance">Preallocation performance </a> <small>Preallocation is a standard Matlab speedup technique. Still, it has several undocumented aspects. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A few months ago, I discussed several <a href="/articles/a-few-parfor-tips" target="_blank">tips regarding Matlab&#8217;s <i><b>parfor</b></i></a> command, which is used by the Parallel Computing Toolbox (PCT) for parallelizing loops. Today I wish to extend that post with some unexplained oddities when using <i><b>parfor</b></i></a>, compared to a standard <i><b>for</b></i> loop.</p>
<h3 id="serialization">Data serialization quirks</h3>
<p><a href="http://www.mathworks.com/matlabcentral/profile/authors/870050-dimitri-shvorob" rel="nofollow" target="_blank">Dimitri Shvorob</a> may not appear at first glance to be a prolific contributor on Matlab Central, but from the little he has posted over the years I regard him to be a Matlab power-user. So when Dimitri reports something, I take it seriously. Such was the case several months ago, when he contacted me regarding very odd behavior that he saw in his code: the <i><b>for</b></i> loop worked well, but the <i><b>parfor</b></i> version returned different (incorrect) results. Eventually, Dimitry traced the problem to something <a href="http://fluffynukeit.com/tag/loadobj" rel="nofollow" target="_blank">originally reported</a> by Dan Austin on his <a href="http://fluffynukeit.com" rel="nofollow" target="_blank">Fluffy Nuke It blog</a>.<br />
The core issue is that if we have a class object that is used within a <i><b>for</b></i> loop, Matlab can access the object directly in memory. But with a <i><b>parfor</b></i> loop, the object needs to be serialized in order to be sent over to the parallel workers, and deserialized within each worker. If this serialization/deserialization process involves internal class methods, the workers might see a different version of the class object than the one seen in the serial <i><b>for</b></i> loop. This could happen, for example, if the serialization/deserialization method croaks on an error, or depends on some dynamic (or random) conditions to create data.<br />
In other words, when we use data objects in a <i><b>parfor</b></i> loop, the data object is not necessarily sent &#8220;as-is&#8221;: additional processing may be involved under the hood that modify the data in a way that may be invisible to the user (or the loop code), resulting in different processing results of the parallel (<i><b>parfor</b></i>) vs. serial (<i><b>for</b></i>) loops.<br />
For additional aspects of Matlab serialization/deserialization, see <a href="/articles/serializing-deserializing-matlab-data" target="_blank">my article</a> from 2 years ago (and its interesting feedback comments).</p>
<h3 id="precision">Data precision quirks</h3>
<p><i>The following section was contributed by guest blogger Lior Perlmuter-Shoshany, head algorithmician at a private equity fund.</i><br />
In my work, I had to work with matrixes in the order of 10<sup>9</sup> cells. To reduce the memory footprint (and hopefully also improve performance), I decided to work with data of type <code>single</code> instead of Matlab&#8217;s default <code>double</code>. Furthermore, in order to speed up the calculation I use <i><b>parfor</b></i> rather than <i><b>for</b></i> in the main calculation. In the end of the run I am running a mini <i><b>for</b></i>-loop to see the best results.<br />
What I discovered to my surprise is that the results from the <b><i>parfor</i></b> and <i><b>for</b></i> loop variants is not the same!<br />
<span id="more-6821"></span><br />
The following simplified code snippet illustrate the problem by calculating a simple standard-deviation (<i><b>std</b></i>) over the same data, in both <code>single</code>&#8211; and <code>double</code>-precision. Note that the loops are ran with only a single iteration, to illustrate the fact that the problem is with the parallelization mechanism (probably the serialization/deserialization parts once again), not with the distribution of iterations among the workers.</p>
<pre lang="matlab">
clear
rng('shuffle','twister');
% Prepare the data in both double and single precision
arr_double = rand(1,100000000);
arr_single = single(arr_double);
% No loop - direct computation
std_single0 = std(arr_single);
std_double0 = std(arr_double);
% Loop #1 - serial for loop
std_single = 0;
std_double = 0;
for i=1
    std_single(i) = std(arr_single);
    std_double(i) = std(arr_double);
end
% Loop #2 - parallel parfor loop
par_std_single = 0;
par_std_double = 0;
parfor i=1
    par_std_single(i) = std(arr_single);
    par_std_double(i) = std(arr_double);
end
% Compare results of for loop vs. non-looped computation
isForSingleOk = isequal(std_single, std_single0)
isForDoubleOk = isequal(std_double, std_double0)
% Compare results of single-precision data (for vs. parfor)
isParforSingleOk = isequal(std_single, par_std_single)
parforSingleAccuracy = std_single / par_std_single
% Compare results of double-precision data (for vs. parfor)
isParforDoubleOk = isequal(std_double, par_std_double)
parforDoubleAccuracy = std_double / par_std_double
</pre>
<p>Output example :</p>
<pre lang="matlab">
isForSingleOk =
    1                   % <= true (of course!)
isForDoubleOk =
    1                   % <= true (of course!)
isParforSingleOk =
    0                   % <= false (odd!)
parforSingleAccuracy =
    0.73895227413361    % <= single-precision results are radically different in parfor vs. for
isParforDoubleOk =
    0                   % <= false (odd!)
parforDoubleAccuracy =
    1.00000000000021    % <= double-precision results are almost [but not exactly] the same in parfor vs. for
</pre>
<p>From my testing, the larger the data array, the bigger the difference is between the results of <code>single</code>-precision data when running in <i><b>for</b></i> vs. <i><b>parfor</b></i>.<br />
In other words, my experience has been that if you have a huge data matrix, it's better to parallelize it in <code>double</code>-precision if you wish to get [nearly] accurate results. But even so, I find it deeply disconcerting that the results are not exactly identical (at least on R2015a-R2016b on which I tested) even for the native <code>double</code>-precision .<br />
Hmmm... bug?</p>
<h3 id="travels">Upcoming travels - Zürich & Geneva</h3>
<p>I will shortly be traveling to clients in Zürich and Geneva, Switzerland. If you are in the area and wish to meet me to discuss how I could bring value to your work with some advanced Matlab consulting or training, then please email me (altmany at gmail):</p>
<ul>
<li><b>Zürich</b>: January 15-17</li>
<li><b>Geneva</b>: January 18-21</li>
</ul>
<p>Happy new year everybody!</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/quirks-with-parfor-vs-for">Quirks with parfor vs. for</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/a-few-parfor-tips" rel="bookmark" title="A few parfor tips">A few parfor tips </a> <small>The parfor (parallel for) loops can be made faster using a few simple tips. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-compilation-quirks-take-2" rel="bookmark" title="Matlab compilation quirks &#8211; take 2">Matlab compilation quirks &#8211; take 2 </a> <small>A few hard-to-trace quirks with Matlab compiler outputs are explained. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/quirks-with-compiled-matlab-dlls" rel="bookmark" title="Quirks with compiled Matlab DLLs">Quirks with compiled Matlab DLLs </a> <small>Several quirks with Matlab-compiled DLLs are discussed and workarounds suggested. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/preallocation-performance" rel="bookmark" title="Preallocation performance">Preallocation performance </a> <small>Preallocation is a standard Matlab speedup technique. Still, it has several undocumented aspects. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/quirks-with-parfor-vs-for/feed</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>Checking status of warning messages in MEX</title>
		<link>https://undocumentedmatlab.com/articles/checking-status-of-warning-messages-in-mex?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=checking-status-of-warning-messages-in-mex</link>
					<comments>https://undocumentedmatlab.com/articles/checking-status-of-warning-messages-in-mex#respond</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 21 Dec 2016 15:24:06 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[Mex]]></category>
		<category><![CDATA[Pavel Holoborodko]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6797</guid>

					<description><![CDATA[<p>Undocumented Mex functions can be used to extract the state of Matlab warnings in run-time. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/checking-status-of-warning-messages-in-mex">Checking status of warning messages in MEX</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/better-mex-error-messages" rel="bookmark" title="Better MEX error messages">Better MEX error messages </a> <small>The default clunky and release-incompatible MEX error messages can be improved using a simple hack. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-status-bar-text" rel="bookmark" title="Setting status-bar text">Setting status-bar text </a> <small>The Matlab desktop and figure windows have a usable statusbar which can only be set using undocumented methods. This post shows how to set the status-bar text....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-status-bar-components" rel="bookmark" title="Setting status-bar components">Setting status-bar components </a> <small>Matlab status-bars are Java containers in which we can add GUI controls such as progress-bars, not just simple text labels...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/sending-email-text-messages-from-matlab" rel="bookmark" title="Sending email/text messages from Matlab">Sending email/text messages from Matlab </a> <small>Sending emails and SMS (text) messages from Matlab is easy, once you know a few quirks....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>Once again I would like to welcome guest blogger Pavel Holoborodko, the developer of the <a href="http://advanpix.com" rel="nofollow" target="_blank">Advanpix Multiprecision Computing Toolbox</a>. Pavel has <a href="/articles/tag/pavel-holoborodko" target="_blank">already posted here</a> as a guest blogger about undocumented Matlab MEX functions. Today he will discuss another little-known aspect of advanced MEX programming with Matlab, a repost of an article that was <a href="http://www.advanpix.com/2016/10/24/check-status-of-warning-messages-from-mex" rel="nofollow" target="_blank">originally posted</a> on his own blog. Happy holidays everybody!</i><br />
Matlab allows flexible adjustment of visibility of warning messages. Some, or even all, messages can be disabled from showing on the screen by <i><b><a href="https://www.mathworks.com/help/matlab/matlab_prog/suppress-warnings.html" rel="nofollow" target="_blank">warning</a></b></i> command.<br />
The little known fact is that status of some warnings may be used to change the execution path in algorithms. For example, if warning <code>'Matlab:nearlySingularMatrix'</code> is disabled, then the linear system solver (<i><b>mldivide</b></i> operator) might skip estimation of reciprocal condition number which is used exactly for the purpose of detection of nearly singular matrices. If the trick is used, it allows 20%-50% boost in solver performance, since <code>rcond</code> estimation is a time consuming process.<br />
Therefore it is important to be able to retrieve status of warnings in Matlab. Especially in MEX libraries targeted for improved performance. Unfortunately Matlab provides no simple way to check status of warning message from MEX module.<br />
Today&#8217;s article outlines two workarounds for the issue:</p>
<ol>
<li>Using <code>mexCallMATLABWithTrap</code> (documented)</li>
<li>Using <code>utGetWarningStatus</code> (undocumented)</li>
</ol>
<p><span id="more-6797"></span></p>
<h3 id="mexCallMATLABWithTrap">Using mexCallMATLABWithTrap (documented)</h3>
<p>The first idea is to use documented <a href="https://www.mathworks.com/help/matlab/apiref/mexcallmatlabwithtrap.html" rel="nofollow" target="_blank"><code>mexCallMATLABWithTrap</code></a> function to execute <i><b>warning</b>(&#8216;query&#8217;,&#8230;)</i> command using Matlab&#8217;s interpreter and then parse the returned result:</p>
<pre lang="cpp">
bool mxIsWarningEnabled(const char* warningId)
{
    bool enabled = true;
    if (NULL != warningId)
    {
        mxArray *mxCommandResponse = NULL, *mxException = NULL;
        mxArray *args[2];
        /* warning('query', warningId); */
        args[0] = mxCreateString("query");
        args[1] = mxCreateString(warningId);
        mxException = mexCallMATLABWithTrap(1,&mxCommandResponse,2,args,"warning");
        if (NULL == mxException && NULL != mxCommandResponse)
        {
            if (mxIsStruct(mxCommandResponse))
            {
                const mxArray* state_field = mxGetField(mxCommandResponse, 0, "state");
                if (mxIsChar(state_field))
                {
                    char state_value[8] = {0};
                    enabled = (0 == mxGetString(state_field, state_value, 8)) &&
                              (0 == strcmp(state_value,"on"));
                }
            }
            mxDestroyArray(mxCommandResponse);
        }
        else
        {
            /* 'warning' returned with error */
            mxDestroyArray(mxException);
        }
        mxDestroyArray(args[0]);
        mxDestroyArray(args[1]);
    }
    return enabled;
}
</pre>
<p>This approach is slow, but works fine in most standard situations. See the bottom of this post for a usage example.<br />
However, this approach has an important drawback – we should be careful with recursive calls to the Matlab interpreter (<code>Matlab -> MEX -> Matlab</code>) and with <a href="http://www.advanpix.com/2016/02/14/short-and-informative-error-messages-from-mex/" rel="nofollow" target="_blank">handling Matlab errors in MEX</a>. It is safe only if we use identical standard libraries and compiler to build both MEX and Matlab.<br />
In other cases, for example when MEX is targeted to work with different versions of Matlab, or was built with a different standard library and compiler, etc. – cross boundary handling of errors (which are just C++ exceptions) might lead to unpredictable results, most likely segfaults.</p>
<h3 id="utGetWarningStatus">Using utGetWarningStatus (undocumented)</h3>
<p>To avoid all the overhead of calling Matlab interpreter and unsafe error handling, we can use some undocumented internal Matlab functions:</p>
<pre lang="cpp">
/* Link with libut library to pick-up undocumented functions: */
extern "C" void* utGetWarningManagerContext(void);
extern "C" bool  utIsValidMessageIdentifier(const char *warningId);
extern "C" bool  utGetWarningStatus(void* context, const char *warningId);
/*
   Returns true if warning with warningId enabled
   Matlab versions supported/tested: R2008b - R2016b
*/
bool mxIsWarningEnabled(const char *warningId)
{
    bool enabled = true;
    if (NULL != warningId && utIsValidMessageIdentifier(warningId))
    {
        void* context = utGetWarningManagerContext();
        enabled = (NULL != context) && utGetWarningStatus(context, warningId);
    }
    return enabled;
}
</pre>
<p>Now the code is clean, fast and safe – we bypass the interpreter and work directly with Matlab kernel. All the undocumented functions involved are present in Matlab for at least 10 years and do simple logical checks under the hood.<br />
The standard function <code><a href="https://www.mathworks.com/help/matlab/apiref/mexwarnmsgidandtxt.html" rel="nofollow" target="_blank">mexWarnMsgIdAndTxt</a></code> uses similar code to check if it should display the warning or just suppress it, and that code remains unchanged since R2008b. This is a good indication of code stability and makes us believe that it will not be changed in future versions of Matlab.<br />
For both workarounds, usage is simple:</p>
<pre lang="cpp">
if (mxIsWarningEnabled("Matlab:nearlySingularMatrix"))
{
   /* compute rcond */
}
else
{
   /* do something else */
}
</pre>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/checking-status-of-warning-messages-in-mex">Checking status of warning messages in MEX</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/better-mex-error-messages" rel="bookmark" title="Better MEX error messages">Better MEX error messages </a> <small>The default clunky and release-incompatible MEX error messages can be improved using a simple hack. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-status-bar-text" rel="bookmark" title="Setting status-bar text">Setting status-bar text </a> <small>The Matlab desktop and figure windows have a usable statusbar which can only be set using undocumented methods. This post shows how to set the status-bar text....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-status-bar-components" rel="bookmark" title="Setting status-bar components">Setting status-bar components </a> <small>Matlab status-bars are Java containers in which we can add GUI controls such as progress-bars, not just simple text labels...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/sending-email-text-messages-from-matlab" rel="bookmark" title="Sending email/text messages from Matlab">Sending email/text messages from Matlab </a> <small>Sending emails and SMS (text) messages from Matlab is easy, once you know a few quirks....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/checking-status-of-warning-messages-in-mex/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Customizing uifigures part 2</title>
		<link>https://undocumentedmatlab.com/articles/customizing-uifigures-part-2?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-uifigures-part-2</link>
					<comments>https://undocumentedmatlab.com/articles/customizing-uifigures-part-2#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 07 Sep 2016 17:00:57 +0000</pubDate>
				<category><![CDATA[Figure window]]></category>
		<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Iliya Romm]]></category>
		<category><![CDATA[uifigure]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6635</guid>

					<description><![CDATA[<p>Matlab's new web-based uifigures can be customized using custom CSS and Javascript code. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2">Customizing uifigures part 2</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-3" rel="bookmark" title="Customizing uifigures part 3">Customizing uifigures part 3 </a> <small>As I have repeatedly posted in recent years, Matlab is advancing towards web-based GUI. The basic underlying technology is more-or-less stable: an HTML/Javascript webpage that is created-on-the-fly and rendered in a stripped-down browser window (based on Chromium-based jxBrowser in recent...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-1" rel="bookmark" title="Customizing uifigures part 1">Customizing uifigures part 1 </a> <small>Matlab's new web-based uifigures can be customized in a variety of undocumented ways. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel" rel="bookmark" title="Customizing web-GUI uipanel">Customizing web-GUI uipanel </a> <small>We can customize Matlab's new web-based GUI panels in many interesting ways. Here's how... ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events" rel="bookmark" title="Matlab callbacks for uifigure JavaScript events">Matlab callbacks for uifigure JavaScript events </a> <small>Matlab callback code can be attached to JavaScript events in web-based uifigures. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I would like to introduce guest blogger Iliya Romm of Israel&#8217;s Technion <a href="http://bcukurel.net.technion.ac.il" target="_blank" rel="nofollow">Turbomachinery and Heat Transfer Laboratory</a>. Today Iliya will discuss how Matlab&#8217;s new web-based figures can be customized with user-controlled CSS and JavaScript code.</i><br />
When we compare the documented properties of a &#8220;classic&#8221; <a href="http://www.mathworks.com/help/matlab/ref/uicontrol-properties.html" target="_blank" rel="nofollow"><code>uicontrol</code></a> with an App Designer control such as <a href="http://www.mathworks.com/help/matlab/ref/checkboxappdesigner-properties.html" target="_blank" rel="nofollow"><code>uicheckbox</code></a>, we see lists of 42 and 15 properties, respectively. At first glance, this implies that our ability to customize App Designer elements is relatively very limited. This is surely a disquieting conclusion, especially for those used to being able to change most aspect of their Matlab figures via Java. Fortunately, such a conclusion is quite far from reality, as we will shortly see.<br />
To understand this claim, we need to consider a <a href="/articles/customizing-uifigures-part-1" target="_blank" rel="nofollow">previous post on this blog</a>, where Yair discussed how uifigures are actually HTML webpages rendered by Matlab. As such, they have a DOM that can be accessed and manipulated through JavaScript commands to achieve various visual customizations. Today we&#8217;ll explore the structure of the uifigure webpage; take a look at some possibilities provided by the Dojo Toolkit; and see how to use Dojo to customize uifigure controls visually using CSS styles and/or HTML attributes.<br />
<center><a href="/images/uifigure_css1.gif" rel="nofollow" target="_blank"><img decoding="async" alt="User customizations of Matlab uifigures (click to zoom-in)" src="https://undocumentedmatlab.com/images/uifigure_css1.gif" title="User customizations of Matlab uifigures (click to zoom-in)" width="75%" style="max-width:1135px;" /></a><br />
User customizations of Matlab uifigures (click to zoom-in)</center><br />
<span id="more-6635"></span></p>
<h3 id="css">A brief introduction to CSS</h3>
<p><b>CSS</b> stands for <b>C</b>ascading <b>S</b>tyle <b>S</b>heets. As described on <a href="https://www.w3.org/standards/webdesign/htmlcss#whatcss" target="_blank" rel="nofollow">the official webpage</a> of W3C (which governs web standards):</p>
<blockquote><p>CSS is the language for describing the presentation of Web pages, including colors, layout, and fonts. CSS is independent of HTML. This is referred to as the separation of structure (or: content) from presentation.</p></blockquote>
<p>CSS rules (or &#8220;styles&#8221;) can be defined in one of three places:</p>
<ul>
<li>A separate file, such as the <i >main.css</i> that Matlab uses for uifigures (this file is found minified in <i>%matlabroot%\toolbox\matlab\uitools\uifigureappjs\release\gbtclient\css</i>)</li>
<li>An inline block inside the HTML&#8217;s <code>&lt;head&gt;</code> section</li>
<li>Directly within a DOM node</li>
</ul>
<p>Deciding which of the above to use, is largely a choice of the right tool for the job. <i>Usually</i>, the first two choices should be preferred, as they adhere to the &#8220;separation of structure and presentation&#8221; idea better. However, in the scope of this demonstration, we’ll be using mostly the 3rd option, because it allows us not to worry about possible CSS precedence issues (<a href="http://vanseodesign.com/css/css-specificity-inheritance-cascaade/" target="_blank" rel="nofollow">suggested read</a>).<br />
The syntax of CSS is generally: <code>selector { property: value }</code>, but it can have <a href="http://www.tutorialspoint.com/css/css_syntax.htm" target="_blank" rel="nofollow">other forms</a> as well.</p>
<h3 id="details">Getting down to business</h3>
<p>Let us consider a very basic uifigure that only contains a <a href="http://www.mathworks.com/help/matlab/ref/uitextarea.html" target="_blank" rel="nofollow"><code>uitextarea</code></a> and its label:<br />
<center><figure style="width: 282px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Simple demo uifigure with a TextArea and label" src="https://undocumentedmatlab.com/images/uifigure_css2.png" title="Simple demo uifigure with a TextArea and label" width="282" height="134" /><figcaption class="wp-caption-text">Simple demo uifigure with a TextArea and label</figcaption></figure></center><br />
The auto-generated code for it is:</p>
<div style="height: 300px; overflow: auto; margin-bottom: 10px;">
<pre lang="matlab">
classdef DOMdemo < matlab.apps.AppBase
    % Properties that correspond to app components
    properties (Access = public)
        UIFigure      matlab.ui.Figure           % UI Figure
        LabelTextArea matlab.ui.control.Label    % Text Area
        TextArea      matlab.ui.control.TextArea % This is some text.
    end
    methods (Access = private)
        % Code that executes after component creation
        function startupFcn(app)
        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 280 102];
            app.UIFigure.Name = 'UI Figure';
            setAutoResize(app, app.UIFigure, true)
            % Create LabelTextArea
            app.LabelTextArea = uilabel(app.UIFigure);
            app.LabelTextArea.HorizontalAlignment = 'right';
            app.LabelTextArea.Position = [16 73 62 15];
            app.LabelTextArea.Text = 'Text Area';
            % Create TextArea
            app.TextArea = uitextarea(app.UIFigure);
            app.TextArea.Position = [116 14 151 60];
            app.TextArea.Value = {'This is some text.'};
        end
    end
    methods (Access = public)
        % Construct app
        function app = DOMdemo()
            % Create and configure components
            createComponents(app)
            % Register the app with App Designer
            registerApp(app, app.UIFigure)
            % Execute the startup function
            runStartupFcn(app, @startupFcn)
            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
</pre>
</div>
<p>Let's say we want to modify certain aspects of the <code>TextArea</code> widget, such as the text color, background, and/or horizontal alignment. The workflow for styling elements involves:</p>
<ol>
<li>Find the handle to the webfigure</li>
<li>Find the DOM node we want to modify</li>
<li>Find the property name that corresponds to the change we want</li>
<li>Find a way to manipulate the desired node from Matlab</li>
</ol>
<h4 id="webfigure">Step 1: Find the handle to the webfigure</h4>
<p>The first thing we need to do is to strategically place a bit of code that would allow us to get the URL of the figure so we can inspect it in our browser:</p>
<pre lang="matlab">
function startupFcn(app)
   % Customizations (aka "MAGIC GOES HERE"):
   warning off Matlab:HandleGraphics:ObsoletedProperty:JavaFrame
   warning off Matlab:structOnObject
   while true
      try
         win = struct(struct(struct(app).UIFigure).Controller).Container.CEF;
         disp(win.URL);
         break
      catch
         disp('Not ready yet!');
         pause(0.5); % Give the figure (webpage) some more time to load
      end
   end
end
</pre>
<p>This code waits until the page is <i>sufficiently</i> loaded, and then retrieve its local address (URL). The result will be something like this, which can be directly opened in any browser (outside Matlab):</p>
<pre lang="none">http://localhost:31415/toolbox/matlab/uitools/uifigureappjs/componentContainer.html?channel=/uicontainer/861ef484-534e-4a50-993e-6d00bdba73a5&snc=88E96E</pre>
<h4 id="DOM">Step 2: Find the DOM node that corresponds to the component that we want to modify</h4>
<p>Loading this URL in an external browser (e.g., Chrome, Firefox or IE/Edge) enables us to use web-development addins (e.g., FireBug) to inspect the page contents (source-code). </p>
<p>Note: in recent Matlab releases, the URL cannot be directly opened in a browser unless we first set Matlab to enable this (<a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events#comment-454673" target="_blank">thanks to Perttu</a>). We can turn on such browser debugging by running:</p>
<pre lang="matlab">matlab.internal.webwindow(' ', 'DebugPort',4040) %note: the space is important!</pre>
<p>before any other App, or kill all MatlabWindow processes (from the operating system's task manager) before running the command. Then browse http://localhost:4040/ in your browser - this will display a list of links, one link for each uifigure, based on the uifigure's title (name); click the requested uifigure's link to see and debug the figure's HTML/CSS contents.</p>
<p>Opening the URL inside a browser and inspecting the page contents, we can see its DOM:<br />
<center><a href="/images/uifigure_css3.png" rel="nofollow" target="_blank"><img decoding="async" alt="Inspecting the DOM in Firefox (click to zoom-in)" src="https://undocumentedmatlab.com/images/uifigure_css3.png" title="Inspecting the DOM in Firefox (click to zoom-in)" width="60%" style="max-width:1197px;" /></a><br />
Inspecting the DOM in Firefox (click to zoom-in)<br />
</center><br />
Notice the three <code>data-tag</code> entries marked by red frames. Any idea why there are exactly three nonempty tags like that? This is because our App Designer object, <code>app</code>, contains 3 declared children, as defined in:</p>
<pre lang="matlab">
createComponents(app):
    app.UIFigure = uifigure;
    app.LabelTextArea = uilabel(app.UIFigure);
    app.TextArea = uitextarea(app.UIFigure);
</pre>
<p>... and each of them is assigned a random hexadecimal id whenever the app is opened.<br />
Finding the relevant node involved some trial-and-error, but after doing it several times I seem to have found a consistent pattern that can be used to our advantage. Apparently, the nodes with <code>data-tag</code> are always above the element we want to style, sometimes as a direct parent and sometimes farther away. So why do we even need to bother with choosing more accurate nodes than these "tagged" ones? Shouldn't styles applied to the tagged nodes <i>cascade</i> down to the element we care about? Sure, <i>sometimes</i> it works like that, but we want to do better than "sometimes". To that end, we would like to select as relevant a node as possible.<br />
Anyway, the next step in the program is to find the data-tag that corresponds to the selected component. Luckily, there is a direct (undocumented) way to get it:</p>
<pre lang="matlab">
% Determine the data-tag of the DOM component that we want to modify:
hComponent = app.TextArea;  % handle to the component that we want to modify
data_tag = char(struct(hComponent).Controller.ProxyView.PeerNode.getId);  % this part is generic: can be used with any web-based GUI component
</pre>
<p>Let's take a look at the elements marked with blue and green borders (in that order) in the DOM screenshot. We see that the <code>data-tag</code> property is exactly one level above these elements, in other words, the first child of the tagged node is an element that contains a <code>widgetid</code> property. This property is very important, as it contains the <code>id</code> of the node that we actually want to change. Think pointers. To summarize this part:<br />
<center><b>data-tag  &nbsp; => &nbsp; widgetid  &nbsp; => &nbsp; widget "handle"</b></center><br />
We shall use this transformation in Step 4 below.<br />
I wanted to start with the blue-outlined element as it demonstrates this structure using distinct elements. The green-outlined element is slightly strange, as it contains a <code>widgetid</code> that points back to itself. Since this obeys the same algorithm, it's not a problem.</p>
<h4 id="propname">Step 3: Find the CSS property name that corresponds to the change we want</h4>
<p>There is no trick here: it's just a matter of going through <a href="http://www.w3schools.com/cssref/default.asp" target="_blank" rel="nofollow">a list of CSS properties</a> and choosing one that "sounds about right" (there are often several ways to achieve the same visual result with CSS). After we choose the relevant properties, we need to convert them to camelCase as per documentation of <a href="https://dojotoolkit.org/reference-guide/1.7/dojo/style.html#tips" target="_blank" rel="nofollow">dojo.style()</a>:</p>
<blockquote><p>If the CSS style property is hyphenated, the JavaScript property is camelCased. For example: "font-size" becomes "fontSize", and so on.</p></blockquote>
<p>Note that Matlab R2016a comes bundled with Dojo v1.10.4, rev. <a href="https://github.com/dojo/dojo/commit/f4fef7077dde783156c1ddd3b06464d236e5537c" target="_blank" rel="nofollow">f4fef70</a> (January 11 2015). Other Matlab releases will probably come with other Dojo versions. They will never be the latest version of Dojo, but rather a version that is 1-2 years old. We should keep this in mind when searching the Dojo documentation. We can get the current Dojo version as follows:</p>
<pre lang="matlab">
>> f=uifigure; drawnow; dojoVersion = matlab.internal.webwindowmanager.instance.windowList(1).executeJS('dojo.version'), delete(f)
dojoVersion =
{"major":1,"minor":10,"patch":4,"flag":"","revision":"f4fef70"}
</pre>
<p>This tells us that Dojo 1.10.4.f4fef70 is the currently-used version. We can use this information to browse the relevant documentation branch, as well as possibly use different Dojo functions/features.</p>
<h4 id="manipulate">Step 4: Manipulate the desired element from Matlab</h4>
<p>In this demo, we'll use a combination of several commands:</p>
<ul>
<li>{matlab.internal.webwindow.}executeJS() – For sending JS commands to the uifigure.</li>
<li><a href="https://dojotoolkit.org/reference-guide/1.10/dojo/query.html" target="_blank" rel="nofollow">dojo.query()</a> – for finding nodes inside the DOM.</li>
<li><a href="https://dojotoolkit.org/reference-guide/1.7/dojo/style.html" target="_blank" rel="nofollow">dojo.style()</a> (deprecated since v1.8) – for applying styles to the required nodes of the DOM.<br />
Syntax: dojo.style(node, style, value); </li>
<li><a href="https://dojotoolkit.org/reference-guide/1.7/dojo/setAttr.html" target="_blank" rel="nofollow">dojo.setAttr</a> (deprecated since v1.8) – for setting some non-style attributes.<br />
Syntax: dojo.setAttr(node, name, value); </li>
</ul>
<p>Consider the following JS commands:</p>
<ul>
<li>search the DOM for nodes having a data-tag attribute having the specified value, take their first child of type <code>&lt;div&gt;</code>, and return the value of this child's <code>widgetid</code> attribute:
<pre lang="matlab">['dojo.getAttr(dojo.query("[data-tag^=''' data_tag '''] > div")[0],"widgetid")']</pre>
</li>
<li>search the DOM for nodes with id of <code>widgetid</code>, then take the first element of the result and set its text alignment:
<pre lang="matlab">['dojo.style(dojo.query("#' widgetId(2:end-1) '")[0],"textAlign","center")']</pre>
</li>
<li>append the CSS style defined by <code>{SOME CSS STYLE}</code> to the page (this style can later be used by nodes):
<pre lang="matlab">['document.head.innerHTML += ''<style>{SOME CSS STYLE}</style>''']);</pre>
</li>
</ul>
<h4 id="all">Putting it all together</h4>
<p>It should finally be possible to understand the code that appears in the animated screenshot at the top of this post:</p>
<pre lang="matlab">
%% 1. Get a handle to the webwindow:
win = struct(struct(struct(app).UIFigure).Controller).Container.CEF;
%% 2. Find which element of the DOM we want to edit (as before):
data_tag = char(struct(app.TextArea).Controller.ProxyView.PeerNode.getId);
%% 3. Manipulate the DOM via a JS command
% ^ always references a class="vc-widget" element.
widgetId = win.executeJS(['dojo.getAttr(dojo.query("[data-tag^=''' data_tag '''] > div")[0],"widgetid")']);
% Change font weight:
dojo_style_prefix = ['dojo.style(dojo.query("#' widgetId(2:end-1) '")[0],'];
win.executeJS([dojo_style_prefix '"fontWeight","900")']);
% Change font color:
win.executeJS([dojo_style_prefix '"color","yellow")']);
% Add an inline css to the HTML <head>:
win.executeJS(['document.head.innerHTML += ''<style>'...
    '@-webkit-keyframes mymove {50% {background-color: blue;}}'...
    '@keyframes mymove {50% {background-color: blue;}}</style>''']);
% Add animation to control:
win.executeJS([dojo_style_prefix '"-webkit-animation","mymove 5s infinite")']);
% Change Dojo theme:
win.executeJS('dojo.setAttr(document.body,''class'',''nihilo'')[0]');
% Center text:
win.executeJS([dojo_style_prefix '"textAlign","center")']);
</pre>
<p>A similar method for center-aligning the items in a <a href="http://www.mathworks.com/help/matlab/ref/uilistbox.html" rel="nofollow" target="_blank">uilistbox</a> is <a href="http://stackoverflow.com/questions/38933254/how-to-customize-app-designer-figures-in-more-ways-than-officially-documented" rel="nofollow" target="_blank">described here</a> (using a CSS <code>text-align</code> directive).<br />
The only thing we need to ensure before running code that manipulates the DOM, is that the page is fully loaded. The easiest way is to include a <i><b>pause</b>()</i> of several seconds right after the <code>createComponents(app)</code> function (this will not interfere with the creation of the uifigure, as it happens on a different thread). I have been experimenting with <a href="https://github.com/StackOverflowMATLABchat/mlapptools/issues/1#issuecomment-241252137" target="_blank" rel="nofollow">another method</a> involving <code>webwindow</code>'s <code>PageLoadFinishedCallback</code> callback, but haven’t found anything elegant yet.</p>
<h3 id="warning">A few words of caution</h3>
<p>In this demonstration, we invoked Dojo functions via the webwindow's JS interface. For something like this to be possible, there has to exist some form of “bridge” that translates Matlab commands to JS commands issued to the browser and control the DOM. We also know that this bridge has to be bi-directional, because binding Matlab callbacks to uifigure actions (e.g. <code>ButtonPushFcn</code> for uibuttons) is a documented feature.<br />
The extent to which the bridge might allow malicious code to control the Matlab process needs to be investigated. Until then, the ability of webwindows to execute arbitrary JS code should be considered a known vulnerability. For more information, see <a href="https://en.wikipedia.org/wiki/Cross-site_scripting" target="_blank" rel="nofollow">XSS</a> and <a href="https://en.wikipedia.org/wiki/Cross-site_scripting#Related_vulnerabilities" target="_blank" rel="nofollow">related</a> vulnerabilities.</p>
<h3 id="conclusion">Final remarks</h3>
<p>It should be clear now that there are actually lots of possibilities afforded by the new uifigures for user customizations. One would hope that future Matlab releases will expose easier and more robust hooks for CSS/JS customizations of uifigure contents. But until that time arrives (if ever), we can make do with the mechanism shown above.<br />
Readers are welcome to visit the <a href="https://github.com/StackOverflowMATLABchat/mlapptools" target="_blank" rel="nofollow">GitHub project</a> dedicated to manipulating uifigures using the methods discussed in this post. Feel free to comment, suggest improvements and ideas, and of course submit some pull requests 🙂<br />
p.s. – it turns out that uifigures can also display <a href="https://www.w3.org/Math/" rel="nofollow" target="_blank">MathML</a>. But this is a topic for another post...</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-2">Customizing uifigures part 2</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-3" rel="bookmark" title="Customizing uifigures part 3">Customizing uifigures part 3 </a> <small>As I have repeatedly posted in recent years, Matlab is advancing towards web-based GUI. The basic underlying technology is more-or-less stable: an HTML/Javascript webpage that is created-on-the-fly and rendered in a stripped-down browser window (based on Chromium-based jxBrowser in recent...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-uifigures-part-1" rel="bookmark" title="Customizing uifigures part 1">Customizing uifigures part 1 </a> <small>Matlab's new web-based uifigures can be customized in a variety of undocumented ways. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-web-gui-uipanel" rel="bookmark" title="Customizing web-GUI uipanel">Customizing web-GUI uipanel </a> <small>We can customize Matlab's new web-based GUI panels in many interesting ways. Here's how... ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events" rel="bookmark" title="Matlab callbacks for uifigure JavaScript events">Matlab callbacks for uifigure JavaScript events </a> <small>Matlab callback code can be attached to JavaScript events in web-based uifigures. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/customizing-uifigures-part-2/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Zero-testing performance</title>
		<link>https://undocumentedmatlab.com/articles/zero-testing-performance?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=zero-testing-performance</link>
					<comments>https://undocumentedmatlab.com/articles/zero-testing-performance#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 31 Aug 2016 17:00:44 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Ken Johnson]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6622</guid>

					<description><![CDATA[<p>Subtle changes in the way that we test for zero/non-zero entries in Matlab can have a significant performance impact. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/zero-testing-performance">Zero-testing performance</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/performance-scatter-vs-line" rel="bookmark" title="Performance: scatter vs. line">Performance: scatter vs. line </a> <small>In many circumstances, the line function can generate visually-identical plots as the scatter function, much faster...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/performance-accessing-handle-properties" rel="bookmark" title="Performance: accessing handle properties">Performance: accessing handle properties </a> <small>Handle object property access (get/set) performance can be significantly improved using dot-notation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/improving-fwrite-performance" rel="bookmark" title="Improving fwrite performance">Improving fwrite performance </a> <small>Standard file writing performance can be improved in Matlab in surprising ways. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/convolution-performance" rel="bookmark" title="Convolution performance">Convolution performance </a> <small>Matlab's internal implementation of convolution can often be sped up significantly using the Convolution Theorem. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I would like to introduce guest blogger <a href="https://www.linkedin.com/in/ken-johnson-b7329610" rel="nofollow" target="_blank">Ken Johnson</a>, a MATLAB Connections partner specializing in <a href="http://www.mathworks.com/products/connections/product_detail/product_35871.html" rel="nofollow" target="_blank">electromagnetic optics simulation</a>. Today Ken will explore some performance subtleties of zero testing in Matlab.</i><br />
I often have a need to efficiently test a large Matlab array for any nonzero elements, e.g.</p>
<pre lang="matlab">
>> a = zeros(1e4);
>> tic, b = any(a(:)~=0); toc
Elapsed time is 0.126118 seconds.
</pre>
<p>Simple enough. In this case, when a is all-zero, the internal search algorithm has no choice but to inspect every element of the array to determine whether it contains any nonzeros. In the more typical case where a contains many nonzeros you would expect the search to terminate almost immediately, as soon as it finds the first nonzero. But that&#8217;s not how it works:</p>
<pre lang="matlab">
>> a = round(rand(1e4));
>> tic, b = any(a(:)~=0); toc
Elapsed time is 0.063404 seconds.
</pre>
<p>There is significant runtime overhead in constructing the logical array &#8220;a(:)~=0&#8221;, although the &#8220;any(&#8230;)&#8221; operation apparently terminates at the first true value it finds.<br />
The overhead can be eliminated by taking advantage of the fact that numeric values may be used as logicals in Matlab, with zero implicitly representing false and nonzero representing true.  Repeating the above test without “~=0”, we get a huge runtime improvement:</p>
<pre lang="matlab">
>> a = round(rand(1e4));
>> tic, b = any(a(:)); toc
Elapsed time is 0.000026 seconds.
</pre>
<p><span id="more-6622"></span><br />
However, there is no runtime benefit when a is all-zero:</p>
<pre lang="matlab">
>> a = zeros(1e4);
>> tic, b = any(a(:)); toc
Elapsed time is 0.125120 seconds.
</pre>
<p><i>(I do not quite understand this. There should be some runtime benefit from bypassing the logical array construction.)</i></p>
<h3 id="nan">NaN values</h3>
<p>There is also another catch: The above efficiency trick does not work when a contains NaN values (if you consider NaN to be nonzero), e.g.</p>
<pre lang="matlab">
>> any([0,nan])
ans =
     0
</pre>
<p>The <i><b>any</b></i> function ignores entries that are NaN, meaning it treats NaNs as zero-equivalent. This is inconsistent with the behavior of the inequality operator:</p>
<pre lang="matlab">
>> any([0,nan]~=0)
ans =
     1
</pre>
<p>To avoid this problem, an explicit <i><b>isnan</b></i> test is needed. Efficiency is not impaired when a contains many nonzeros, but there is a 2x efficiency loss when a is all-zero:</p>
<pre lang="matlab">
>> a = round(rand(1e4));
>> tic, b = any(a(:)) || any(isnan(a(:))); toc
Elapsed time is 0.000027 seconds.
>> a = zeros(1e4);
>> tic, b = any(a(:)) || any(isnan(a(:))); toc
Elapsed time is 0.256604 seconds.
</pre>
<p>For testing all-nonzero the NaN problem does not occur:</p>
<pre lang="matlab">
>> all([1 nan])
ans =
     1
</pre>
<p>In this context NaN is treated as nonzero and the all-nonzero test is straightforward:</p>
<pre lang="matlab">
>> a = round(rand(1e4));
>> tic, b = all(a(:)); toc
Elapsed time is 0.000029 seconds.
</pre>
<p>For testing any-zero and all-zero, use the complements of the above tests:</p>
<pre lang="matlab">
>> b = ~any(a(:)) || any(isnan(a(:)));  % all zero?
>> b = ~all(a(:));  % any zero?
</pre>
<h3 id="find">Efficient <i>find</i></h3>
<p>The <i><b>find</b></i> operation can also be optimized by bypassing construction of a logical temporary array, e.g.</p>
<pre lang="matlab">
>> a = round(rand(1e4));
>> tic, b = find(a(:)~=0, 1); toc
Elapsed time is 0.065697 seconds.
>> tic, b = find(a(:), 1); toc
Elapsed time is 0.000029 seconds.
</pre>
<p>There is no problem with NaNs in this case; the <i><b>find</b></i> function treats NaN as nonzero, e.g.</p>
<pre lang="matlab">
>> find([0,nan,1], 1)
ans =
     2
</pre>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/zero-testing-performance">Zero-testing performance</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/performance-scatter-vs-line" rel="bookmark" title="Performance: scatter vs. line">Performance: scatter vs. line </a> <small>In many circumstances, the line function can generate visually-identical plots as the scatter function, much faster...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/performance-accessing-handle-properties" rel="bookmark" title="Performance: accessing handle properties">Performance: accessing handle properties </a> <small>Handle object property access (get/set) performance can be significantly improved using dot-notation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/improving-fwrite-performance" rel="bookmark" title="Improving fwrite performance">Improving fwrite performance </a> <small>Standard file writing performance can be improved in Matlab in surprising ways. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/convolution-performance" rel="bookmark" title="Convolution performance">Convolution performance </a> <small>Matlab's internal implementation of convolution can often be sped up significantly using the Convolution Theorem. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/zero-testing-performance/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>rmfield performance</title>
		<link>https://undocumentedmatlab.com/articles/rmfield-performance?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rmfield-performance</link>
					<comments>https://undocumentedmatlab.com/articles/rmfield-performance#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 25 May 2016 07:00:48 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Hanan Kavitz]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6427</guid>

					<description><![CDATA[<p>The performance of the builtin rmfield function (as with many other builtin functions) can be improved by simple profiling. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/rmfield-performance">rmfield performance</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-java-memory-leaks-performance" rel="bookmark" title="Matlab-Java memory leaks, performance">Matlab-Java memory leaks, performance </a> <small>Internal fields of Java objects may leak memory - this article explains how to avoid this without sacrificing performance. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/callback-functions-performance" rel="bookmark" title="Callback functions performance">Callback functions performance </a> <small>Using anonymous functions in Matlab callbacks can be very painful for performance. Today's article explains how this can be avoided. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/array-resizing-performance" rel="bookmark" title="Array resizing performance">Array resizing performance </a> <small>Several alternatives are explored for dynamic array growth performance in Matlab loops. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-performance" rel="bookmark" title="Plot performance">Plot performance </a> <small>Undocumented inner plot mechanisms can significantly improve plotting performance ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>Once again I would like to introduce guest blogger <a href="http://www.mathworks.com/matlabcentral/profile/authors/2392999-hanan-kavitz" rel="nofollow" target="_blank">Hanan Kavitz</a> of <a href="http://appliedmaterials.com" rel="nofollow" target="_blank">Applied Materials</a>. Several months ago Hanan discussed some <a href="/articles/quirks-with-compiled-matlab-dlls" target="_blank">quirks with compiled Matlab DLLs</a>. Today Hanan will discuss how they overcame a performance bottleneck with Matlab&#8217;s builtin <b>rmfield</b> function, exemplifying the general idea that we can sometimes improve performance by profiling the core functionality that causes a performance hotspot and optimizing it, even when it is part of a builtin Matlab function. For additional ideas of improving Matlab peformance, search this blog for <a href="/tag/performance" target="_blank">&#8220;Performance&#8221; articles</a>, and/or get the book &#8220;<a href="/books/matlab-performance" target="_blank">Accelerating MATLAB Performance</a>&#8220;.</i><br />
<span class="alignright"><a href="/books/matlab-performance" target="_blank"><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/speedometer3b3c.gif" alt="Accelerating MATLAB Performance" title="Accelerating MATLAB Performance" width="276" height="275" /></a></span></p>
<p>I&#8217;ve been using Matlab for many years now and from time to time I need to profile low-throughput code. When I profile this code sometimes I realize that a computational &#8216;bottleneck&#8217; is due to a builtin Matlab function (part of the core language). I can often find ways to accelerate such builtin functions and get significant speedup in my code.</p>
<p>I recently found Matlab&#8217;s builtin <i><b>rmfield</b></i> function being too slow for my needs. It works great when one needs to remove a few fields from a small structure, but in our case we needed to remove thousands of fields from a structure containing about 5000 fields – and this is executed in a function that is called many times inside an external loop. The program was significantly sluggish.</p>
<p>It started when a co-worker asked me to look at a code that looked just slightly more intelligent than this:</p>
<pre lang="matlab">
for i = 1:5000
    myStruct = rmfield(myStruct,fieldNames{i});
end
</pre>
<p>Running this code within a tic/toc pair yielded the following results:</p>
<pre lang="matlab">
>> tic; myFunc(); t1 = toc
t1 =
      25.7713
</pre>
<p>In my opinion 25.77 secs for such a simple functionality seems like an eternity&#8230;<br />
<span id="more-6427"></span></p>
<p>The obvious thing was to change the code to the <a href="http://www.mathworks.com/help/matlab/ref/rmfield.html" rel="nofollow" target="_blank">documented</a> faster (vectorized) version:</p>
<pre lang="matlab">
>> tic; myStruct = rmfield(myStruct,fieldNames); t2 = toc
t2 =
      0.6097
</pre>
<p>This is obviously much better but since rmfield is called many times in my application, I needed something even better. So I profiled rmfield and was not happy with the result.</p>
<p>The original code of <i><b>rmfield</b></i> (<i>%matlabroot%/toolbox/matlab/datatypes/rmfield.m</i>) looks something like this (I deleted some non-essential code for brevity):</p>
<pre lang="matlab" highlight="9">
function t = rmfield(s,field)

  % get fieldnames of struct
  f = fieldnames(s);

  % Determine which fieldnames to delete.
  idxremove = [];
  for i=1:length(field)
    j = find(strcmp(field{i},f) == true);
    idxremove = [idxremove;j];
  end

  % set indices of fields to keep
  idxkeep = 1:length(f);
  idxkeep(idxremove) = [];

  % remove the specified fieldnames from the list of fieldnames.
  f(idxremove,:) = [];

  % convert struct to cell array
  c = struct2cell(s);

  % find size of cell array
  sizeofarray = size(c);
  newsizeofarray = sizeofarray;

  % adjust size for fields to be removed
  newsizeofarray(1) = sizeofarray(1) - length(idxremove);

  % rebuild struct
  t = cell2struct(reshape(c(idxkeep,:),newsizeofarray),f);
</pre>
<p>When I profiled the code, the highlighted row was the bottleneck I was looking for.</p>
<p>First, I noticed the string comparison equals to <code>true</code> part &#8211; while <code>'==true'</code> is not the cause of the bottleneck, it does leave an impression of bad coding style 🙁 Perhaps this code was created as some apprentice project, which might also explain its suboptimal performance.</p>
<p>The real performance problem here is that for each field that we wish to remove, <i><b>rmfield</b></i> compares it to all existing fields to find its location in a cell array of field names. This is algorithmically inefficient and makes the code hard to understand (just try &#8211; it took me hard, long minutes).</p>
<p>So, I created a variant of <i>rmfield.m</i> called <i>fast_rmfield.m</i>, as follows (again, omitting some non-essential code):</p>
<pre lang="matlab">
function t = fast_rmfield(s,field)
  % get fieldnames of struct
  f = fieldnames(s);
  [f,ia] = setdiff(f,field,'R2012a');

  % convert struct to cell array
  c = squeeze(struct2cell(s));

  % rebuild struct
  t = cell2struct(c(ia,:),f)';
</pre>
<p>This code is much shorter, easier to explain and maintain, but also (and most importantly) much faster:</p>
<pre lang="matlab">
>> tic; myStruct = fast_rmfield(myStruct,fieldNames); t3 = toc
t3 =
      0.0302
>> t2/t3
ans =
      20.1893
</pre>
<p>This resulted in a speedup of ~850x compared to the original version (of 25.77 secs), and ~20x compared to the vectorized version. A nice improvement in my humble opinion&#8230;</p>
<p>The point in all this is that we can and should rewrite Matlab builtin functions when they are too slow for our needs, whether it is found to be an algorithmic flaw (as in this case), extraneous sanity checks (as in the case of <a href="/articles/ismembc-undocumented-helper-function" target="_blank"><i><b>ismember</b></i></a> or <a href="/articles/datenum-performance" target="_blank"><i><b>datenum</b></i></a>), bad default parameters (as in the case of <a href="/articles/improving-fwrite-performance" target="_blank"><i><b>fopen/fwrite</b></i></a> or <a href="/articles/undocumented-scatter-plot-behavior" target="_blank"><i><b>scatter</b></i></a>), or merely slow implementation (as in the case of <a href="/articles/improving-save-performance" target="_blank"><i><b>save</b></i></a>, <a href="/articles/cellfun-undocumented-performance-boost" target="_blank"><i><b>cellfun</b></i></a>, or the <a href="/articles/convolution-performance" target="_blank"><i><b>conv</b></i> family of functions</a>).</p>
<p>A good pattern is to save such code pieces in file names that hint to the original code. In our case, I used <i><b>fast_rmfield</b></i> to suggest that it is a faster alternative to <i><b>rmfield</b></i>.</p>
<p><i>Do you know of any other example of a slow implementation in a built-in Matlab function that can be optimized? If so, please leave a comment below.</i></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/rmfield-performance">rmfield performance</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-java-memory-leaks-performance" rel="bookmark" title="Matlab-Java memory leaks, performance">Matlab-Java memory leaks, performance </a> <small>Internal fields of Java objects may leak memory - this article explains how to avoid this without sacrificing performance. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/callback-functions-performance" rel="bookmark" title="Callback functions performance">Callback functions performance </a> <small>Using anonymous functions in Matlab callbacks can be very painful for performance. Today's article explains how this can be avoided. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/array-resizing-performance" rel="bookmark" title="Array resizing performance">Array resizing performance </a> <small>Several alternatives are explored for dynamic array growth performance in Matlab loops. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/plot-performance" rel="bookmark" title="Plot performance">Plot performance </a> <small>Undocumented inner plot mechanisms can significantly improve plotting performance ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/rmfield-performance/feed</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>Secure SSL connection between Matlab and PostgreSQL</title>
		<link>https://undocumentedmatlab.com/articles/secure-ssl-connection-between-matlab-and-postgresql?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=secure-ssl-connection-between-matlab-and-postgresql</link>
					<comments>https://undocumentedmatlab.com/articles/secure-ssl-connection-between-matlab-and-postgresql#respond</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 18 Mar 2016 10:39:49 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Jeff Mandel]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6318</guid>

					<description><![CDATA[<p>It is tricky, but quite possible, to use SSL to connect Matlab to a PostgreSQL database. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/secure-ssl-connection-between-matlab-and-postgresql">Secure SSL connection between Matlab and PostgreSQL</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/speeding-up-matlab-jdbc-sql-queries" rel="bookmark" title="Speeding up Matlab-JDBC SQL queries">Speeding up Matlab-JDBC SQL queries </a> <small>Fetching SQL ResultSet data from JDBC into Matlab can be made significantly faster. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-sqlite-in-matlab" rel="bookmark" title="Using SQLite in Matlab">Using SQLite in Matlab </a> <small>SQLite databases can be accessed in a variety of different ways in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/fixing-matlabs-actxserver" rel="bookmark" title="Fixing Matlab&#039;s actxserver">Fixing Matlab&#039;s actxserver </a> <small>Matlab's COM (ActiveX) server behavior can be fixed in a couple of useful manners. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-compilation-quirks-take-2" rel="bookmark" title="Matlab compilation quirks &#8211; take 2">Matlab compilation quirks &#8211; take 2 </a> <small>A few hard-to-trace quirks with Matlab compiler outputs are explained. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I&#8217;d like to introduce guest blogger <a href="http://www.med.upenn.edu/apps/faculty/index.php/g275/p40141" rel="nofollow" target="_blank">Jeff Mandel</a> of the Perelman School of Medicine at the University of Pennsylvania. Today Jeff will discuss a how-to guide for setting up an SSL connection between Matlab and a PostgreSQL database. While this specific topic may be of interest to only a few readers, it involves hard-to-trace problems that are not well documented anywhere. The techniques discussed below may also be applicable, with necessary modifications, to other SSL targets and may thus be of use to a wider group of Matlab users.</i><br />
<span class="alignright"><a href="http://postgresql.org" target="_blank"><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/PostgreSQL.gif" alt="PostgreSQL database" title="PostgreSQL database" width="200" height="200" /></a></span><br />
I&#8217;m developing software for pharmacokinetic control, and needed secure access to a central database from users at remote sites. The client software is written in Matlab, and while I have targeted MacOS, this could be adapted to Windows fairly easily. Hopefully, this will save someone the week it took me to figure all this out.<br />
My environment:</p>
<ul>
<li>PostgreSQL 9.4 installed on the server (Windows 7 PC, but Linux would be equally good)</li>
<li>DynDNS CNAME pointing at the server (diseserver.mydomain.org)</li>
<li>CACert.org registration for domain mydomain.org</li>
<li>Matlab 2015b running on El Capitan</li>
</ul>
<p>Here are the neccesary steps:<br />
<span id="more-6318"></span></p>
<ol>
<li>First, we need a certificate for the server. We can generate this with <a href="http://www.openssl.org" rel="nofollow" target="_blank">OpenSSL</a>:
<pre lang="bash">$openssl req -out diseserver.csr -new -newkey rsa:2048 -nodes -keyout diseserver.key</pre>
<p>Specify any information you want on the key, but ensure <code>CN=diseserver.mydomain.org</code>.</li>
<li>Paste the resulting <i>diseserver.csr</i> file into a new key request at <a href="http://cacert.org" rel="nofollow" target="_blank">CACert.org</a>. Save the resulting certificate as <i>diseserver.crt</i> on your machine.</li>
<li>While still at CACert.org, grab the Class 1 root certificate and save it as <i>root.crt</i>.</li>
<li>Put the files <i>diseserver.key</i>, <i>diseserver.crt</i>, and <i>root.crt</i> in the PostgreSQL data directory.</li>
<li>Edit your <i>postgresql.conf</i> file:
<pre lang="bash">
ssl = on
ssl_cert_file = 'diseserver.crt'  # (change requires restart)
ssl_key_file  = 'diseserver.key'  # (change requires restart)
ssl_ca_file   = 'root.crt'        # (change requires restart)
</pre>
</li>
<li>Restart the PostgreSQL server. The server will now permit SSL connections, a necessary pre-condition for certificate authentication.</li>
<li>We now add 2 lines to <i>pg_hba.conf</i>:
<pre lang="text">
hostnossl  all    all   0.0.0.0/0   reject
hostssl	 mytable  all   0.0.0.0/0   cert map=ssl clientcert=1
</pre>
<p>The first line causes all non-SSL connections to be rejected. The second allows certificate logins for mytable using the map ssl that is defined in <i>pg_ident.conf</i>:</p>
<pre lang="matlab">ssl  /^(.*).mydomain\.org$ \1</pre>
<p>this line extracts the username prefix from <code>CN=username.mydomain.org</code>.</li>
<li>Now we need to generate client certificates. PostgreSQL expects these to be in <i>~/.postgresql</i> (Windows <i>%appdata%\postgresql\</i>):
<pre lang="bash">
$mkdir ~/.postgresql
$cd ~/.postgresql
$openssl req -out postgresql.csr -new -newkey rsa:2048 -nodes -keyout postgresql.key
</pre>
<p>for this key, make <code>CN=username.mydomain.org</code>.</li>
<li>Again, paste the resulting <i>postgresql.csr</i> file into CACert.org, saving the certificate as <i>postgresql.crt</i>.</li>
<li>Test this:
<pre lang="bash">$psql "sslmode=verify-full host=diseserver.mydomain.org dbname=effect user=username"</pre>
<p>The server should respond:</p>
<pre lang="text">
psql (9.4.6, server 9.4.1)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
</pre>
</li>
<li>Next we need to convert our key into pkcs8 format so that Java can read it:
<pre lang="bash">$openssl pkcs8 -topk8 -inform PEM -outform DER -in postgresql.key -out postgresql.pk8 -nocrypt</pre>
</li>
<li>Next, ensure that we have the correct version of the JDBC driver (Java-to-database connector). From the Mac command line:
<pre lang="bash">
$java -version
java version "1.8.0_05"
</pre>
<p>and in Matlab:</p>
<pre lang="matlab">
>> version -java
ans =
Java 1.7.0_75-b13 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
</pre>
<p>This shows that although we have Java 8 installed on El Capitan (at the OS level), Matlab uses a private Java 7 version. So we need the correct version of the jdbc on our <a href="/articles/static-java-classpath-hacks" target="_blank">static java classpath that is used by Matlab</a>:</p>
<pre lang="text">~/Matlab/postgresql-9.4.1208.jre7.jar</pre>
</li>
<li>The next part is very poorly documented in both the MathWorks and the PostgreSQL documentation, but I found it in Russel Gray&#8217;s <a href="https://basildoncoder.com/blog/postgresql-jdbc-client-certificates.html" rel="nofollow" target="_blank"><i>Basildon Coder</i></a> blog: We need to use the jdbc postgresql driver to check the client certificate. To do this, we need a custom SSLSocketFactory &#8211; LibPQFactory. This will grab our certificate and key from <i>~/.postgresql</i> and present them to the server. The url is (note the trailing &#038;):
<pre lang="text">jdbc:postgresql://diseserver.mydomain.org/mytable?ssl=true&sslfactory=org.postgresql.ssl.jdbc4.LibPQFactory&sslmode=verify-full&</pre>
</li>
<li>Next we need the username. Rather than hard-coding this in the source code, we get the system username:
<pre lang="matlab">>> username = java.lang.System.getProperty('user.name');</pre>
</li>
<li>Bundle this all up in a Matlab function, stripping the trailing CR from the username:
<pre lang="matlab">
function dbtest
   driver = 'org.postgresql.Driver';
   [~,username] = system('whoami');
   url = 'jdbc:postgresql://diseserver.mydomain.org/mytable?ssl=true&sslfactory=org.postgresql.ssl.jdbc4.LibPQFactory&sslmode=verify-full&';
   myconn = database('mytable', username, '', driver, url);
   if ~isempty(myconn.Message)
      fprintf(2,'%s\n', myconn.Message);
   else
      fprintf(1, 'Connected!\n');
   end
end
</pre>
</li>
</ol>
<p>Now we can connect from the Matlab command line or a Matlab program.<br />
What if we&#8217;re deployed? We also need to add the contents of our <i>.postgresql</i> directory, plus the jdbc jar file to our deployed app:</p>
<pre lang="matlab">>> mcc -m dbtest.m -a ~/.postgresql -a ~/Matlab/postgresql-9.4.1208.jre7.jar</pre>
<p>Let&#8217;s test the compiled program from the OS command line:</p>
<pre lang="bash">
$./run_dbtest.sh /Applications/Matlab/Matlab_Runtime/v90
Connected!
</pre>
<p>Note that the key and certificates are part of the encrypted bundle produced by Matlab&#8217;s <i><b>mcc</b></i> compiler.<br />
I hope this helps someone!<br />
<i><u>Yair&#8217;s note</u>: the Matlab code above uses Matlab&#8217;s Database Toolbox (specifically, the <b>database</b> function) to connect to the database. In future posts I plan to show how we can connect Matlab directly to a database via JDBC. This topic is covered in detail in chapter 2 of my <a href="/books/matlab-java" rel="nofollow" target="_blank">Matlab-Java programming secrets book</a>.<br />
p.s. &#8211; this blog celebrates a 7-year anniversary tomorrow: I published my very first post here on March 19, 2009, showing <a href="/articles/changing-matlab-command-window-colors" target="_blank">how to change Matlab&#8217;s command-window colors</a> (a post that later led to the now-famous <a href="/articles/cprintf" target="_blank"><b>cprintf</b> utility</a>). It&#8217;s been a long and very interesting ride indeed, but I have no plans to retire anytime soon 🙂</i></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/secure-ssl-connection-between-matlab-and-postgresql">Secure SSL connection between Matlab and PostgreSQL</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/speeding-up-matlab-jdbc-sql-queries" rel="bookmark" title="Speeding up Matlab-JDBC SQL queries">Speeding up Matlab-JDBC SQL queries </a> <small>Fetching SQL ResultSet data from JDBC into Matlab can be made significantly faster. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-sqlite-in-matlab" rel="bookmark" title="Using SQLite in Matlab">Using SQLite in Matlab </a> <small>SQLite databases can be accessed in a variety of different ways in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/fixing-matlabs-actxserver" rel="bookmark" title="Fixing Matlab&#039;s actxserver">Fixing Matlab&#039;s actxserver </a> <small>Matlab's COM (ActiveX) server behavior can be fixed in a couple of useful manners. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-compilation-quirks-take-2" rel="bookmark" title="Matlab compilation quirks &#8211; take 2">Matlab compilation quirks &#8211; take 2 </a> <small>A few hard-to-trace quirks with Matlab compiler outputs are explained. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/secure-ssl-connection-between-matlab-and-postgresql/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
