<?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>MCOS &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/mcos/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Fri, 30 Sep 2022 14:59:20 +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>Setting class property types &#8211; take 2</title>
		<link>https://undocumentedmatlab.com/articles/setting-class-property-types-2?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=setting-class-property-types-2</link>
					<comments>https://undocumentedmatlab.com/articles/setting-class-property-types-2#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 27 Apr 2016 20:20:22 +0000</pubDate>
				<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[MCOS]]></category>
		<category><![CDATA[Object oriented]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6390</guid>

					<description><![CDATA[<p>R2016a saw the addition of class property types. However, a better alternative has existed for many years. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/setting-class-property-types-2">Setting class property types &#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/setting-class-property-types" rel="bookmark" title="Setting class property types">Setting class property types </a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/types-of-undocumented-matlab-aspects" rel="bookmark" title="Types of undocumented Matlab aspects">Types of undocumented Matlab aspects </a> <small>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Three years ago, almost to the day, I wrote about a very handy undocumented feature of Matlab classes that enables us to specify <a href="/articles/setting-class-property-types" target="_blank">type restrictions for any Matlab class property</a>. We can specify property type (for example, <code>char</code>, <code>double</code> or any Matlab class) as well as dimensionality (<code>scalar</code>, <code>vector</code>, or <code>matrix</code>) and complexity indication (<code>complex</code>). Doing so has multiple benefits for code performance, robustness and maintainability. For example:</p>
<pre lang="matlab">
% Undocumented syntax - works well since at least R2010a (possibly earlier)
classdef Packet
    properties
        PacketType@char
        HeaderLength@uint16
        PayloadLength@uint16 scalar = uint16(0);  % initial value
        PacketData@uint8 vector
    end
end
</pre>
<p>In the recent release of Matlab R2016a, a similar feature have finally become fully supported and <a href="http://www.mathworks.com/help/matlab/matlab_oop/restrict-class-of-properties.html" rel="nofollow" target="_blank">documented</a>. The corresponding snippet above would look something like this:</p>
<pre lang="matlab">
% Documented syntax - only works in R2016a or newer
classdef Packet
    properties
        PacketType char
        HeaderLength uint16
        PayloadLength uint16 = uint16(0);  % initial value
        PacketData uint8
    end
end
</pre>
<p>Unfortunately, I dislike the new documented functionality, so I didn&#8217;t feel like promoting it in this blog when it came out. But since a blog reader <a href="/articles/setting-class-property-types#comment-374984" target="_blank">mentioned it</a> a few days ago, I wanted to come out publicly with my opinion and a detailed explanation.<br />
<span id="more-6390"></span><br />
If you look closely at the code snippets above, you will notice two important differences:</p>
<ol>
<li>The &#8220;@&#8221; symbol was replaced with a space</li>
<li>The dimensionality and complexity cannot be specified</li>
</ol>
<p>The new syntax has some drawbacks compared to the previous (undocumented) one:</p>
<ol>
<li><b>Backward compatibility</b> &#8211; We can run the older (undocumented) syntax on any Matlab release since who-knows-when (at least as far back as R2010a [tested], and possibly older releases [untested]), including the very latest R2016a. On the other hand, the new (documented) syntax will only work on R2016a and will crash the program if you try to run it in older releases. This is not even something that you can catch with a try-catch block &#8211; the class will simply not load on any older Matlab release. If you need your code to run on older releases in addition to 16a, you have no choice other than to use the older syntax.</li>
<li><b>Dimensionality</b> &#8211; the new syntax, unlike the undocumented syntax, does not enable users to limit the data dimensionality (scalar/vector/array). This is a very important feature for program robustness and maintainability. Complexity is another type limitation that is missing, although it is less important than the dimensionality. And just in case you were wondering &#8211; the new syntax does <i>not</i> accept the additional <code>scalar</code>, <code>vector</code>, <code>matrix</code> and <code>complex</code> attributes like the older syntax; using them with the new syntax evokes an error.</li>
<li><b>Cross compatibility</b> &#8211; it is very confusing to users coming to Matlab from other programming languages, all of which (without any important exception) place the type name to the LEFT of the identifier name, not to its RIGHT. People coding in both Matlab and Java/C/C++ would easily get confused and frustrated.</li>
<li><b>Consistency</b> &#8211; despite what I hoped, the new syntax still does not apply to function input args: we cannot (AFAIK) limit the input/output args of methods/functions in the same way that we can limit properties. If there&#8217;s a way to do this, I&#8217;d be delighted to learn (<a href="/articles/setting-class-property-types#comment-343150" target="_blank">this comment</a> may indicate that it is work in progress). It is true that this feature is not a drawback of the new syntax compared to the older one, since the old syntax didn&#8217;t have it either (AFAIK). But I would have expected a documented feature to be consistent across the Matlab language (or at least across the MCOS subset), and unfortunately the new feature fails this test.</li>
</ol>
<p>In fact, aside from the fact that the new syntax is documented, I can see no advantages that it offers over the older syntax, only disadvantages. Or am I missing something? Please do tell if you see any important advantages that I&#8217;ve missed.<br />
Luckily for us, <b>the old syntax remains operational, side-by-side with the new one</b>. This enables us to keep running our existing code without worrying [too much] that it might break in R2016a. Maybe the new syntax will grow on me (or improve) in upcoming years, but for the time being I see no benefit in switching away from the @ syntax.<br />
For the past few years, I hoped that the property typing feature will become documented and that it will be a continuation of the undocumented syntax rather than what eventually aired. I&#8217;m afraid it&#8217;s too late to revert it now that it has&#8230; Realistically speaking, the best we can hope for now is for the older syntax to remain operational, and not be withdrawn in some future Matlab release. Making the undocumented syntax documented as-is would be great, but I&#8217;m afraid it is unrealistic given the new circumstances.<br />
I&#8217;m sorry if I take the wind off MathWorks&#8217; sails a bit here, but MathWorks knows that it can count on me to speak my mind without bullshit. Sometimes for the good, sometimes not. All in good spirit and the common interest of improving Matlab over time. No offence intended &#8211; it&#8217;s just my personal opinion after all.<br />
In my opinion this is one of those rare cases where the developers obviously intended to make something better but eventually came out with something worse. They should have stuck to what was. After all, the first and foremost rule of engineering is, and always was:<br />
<center><i><b><font size="+3" color="red">Don&#8217;t fix it if it ain&#8217;t broke!</font></b></i></center></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/setting-class-property-types-2">Setting class property types &#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/setting-class-property-types" rel="bookmark" title="Setting class property types">Setting class property types </a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/types-of-undocumented-matlab-aspects" rel="bookmark" title="Types of undocumented Matlab aspects">Types of undocumented Matlab aspects </a> <small>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/setting-class-property-types-2/feed</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>Solving a Matlab MCOS bug</title>
		<link>https://undocumentedmatlab.com/articles/solving-a-matlab-mcos-bug?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=solving-a-matlab-mcos-bug</link>
					<comments>https://undocumentedmatlab.com/articles/solving-a-matlab-mcos-bug#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 02 Dec 2015 15:55:21 +0000</pubDate>
				<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[MCOS]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6100</guid>

					<description><![CDATA[<p>Matlab has a bug with handling multi-element class-access constructs. This post explains the problem and solution. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/solving-a-matlab-mcos-bug">Solving a Matlab MCOS bug</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/solving-a-matlab-hang-problem" rel="bookmark" title="Solving a Matlab hang problem">Solving a Matlab hang problem </a> <small>A very common Matlab hang is apparently due to an internal timing problem that can easily be solved. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/solving-a-matlab-bug-by-subclassing" rel="bookmark" title="Solving a MATLAB bug by subclassing">Solving a MATLAB bug by subclassing </a> <small>Matlab's Image Processing Toolbox's impoint function contains an annoying bug that can be fixed using some undocumented properties....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/solving-an-mput-ftp-hang-problem" rel="bookmark" title="Solving an mput (FTP) hang problem">Solving an mput (FTP) hang problem </a> <small>Matlab may hang when using passive FTP commands such as mput and dir. A simple workaround is available to fix this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/types-of-undocumented-matlab-aspects" rel="bookmark" title="Types of undocumented Matlab aspects">Types of undocumented Matlab aspects </a> <small>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A few days ago, one of my consulting clients asked me to help him with a very strange problem: he had a Matlab class having a <code>constant</code> property that holds a reference to some handle class object. The problem was that when he tried to modify the property&#8217;s inner values he got Matlab run-time errors because the inner value apparently remained unmodified!<br />
Here is a distilled version of my client&#8217;s classes:</p>
<pre lang='matlab'>
classdef (Abstract) MainClass
    properties (Constant)
        inner = InnerClass
    end
    methods (Static)
        function setInnerValue(newValue)
            MainClass.inner.value1 = newValue;
        end
    end
end
classdef InnerClass < handle
    properties
        value1
        value2
    end
end
</pre>
<p>And the strange run-time behavior:</p>
<div class="wp_syntax">
<div class="code">
<pre class="matlab" style="font-family:monospace;">&gt;&gt; MainClass.<span style="">inner</span>.<span style="">value1</span> = <span style="color: #33f;">5</span>
MainClass =
    inner: <span style="color: #080;">[</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">]</span>
&nbsp;
&gt;&gt; MainClass.<span style="">inner</span>.<span style="">value2</span>  <span style="color: #228B22;">% causes a strange run-time error!</span>
<span style="color:#FF0000;">Reference to non-existent field 'value2'.</span>
&nbsp;
&gt;&gt; MainClass.<span style="">inner</span>.<span style="">value1</span>  <span style="color: #228B22;">% strange - value1 appears unmodified!</span>
ans =
     <span style="color: #080;">[</span><span style="color: #080;">]</span>
&nbsp;
&gt;&gt; MainClass.<span style="">inner</span>  <span style="color: #228B22;">% strange - value1 appears ok here, but where is value2 ?!</span>
ans =
    value1: <span style="color: #33f;">5</span>
&nbsp;
&gt;&gt; MainClass.<span style="">setInnerValue</span><span style="color: #080;">(</span><span style="color: #33f;">7</span><span style="color: #080;">)</span>  <span style="color: #228B22;">% another strange run-time error!</span>
<span style="color:#FF0000;">Reference to non-existent field 'setInnerValue'.</span>
&nbsp;
&gt;&gt; <span style="color: #0000FF;">clear</span> classes  <span style="color: #228B22;">% let's try it afresh...</span>
&gt;&gt; MainClass.<span style="">setInnerValue</span><span style="color: #080;">(</span><span style="color: #33f;">7</span><span style="color: #080;">)</span>  <span style="color: #228B22;">% looks ok, no error...</span>
&gt;&gt; MainClass.<span style="">inner</span>   <span style="color: #228B22;">% strange - now we have both value1 &amp; value2, but value1 is not updated!</span>
ans =
  <span style="color: #0000FF;">InnerClass</span> with properties:
&nbsp;
    value1: <span style="color: #080;">[</span><span style="color: #080;">]</span>
    value2: <span style="color: #080;">[</span><span style="color: #080;">]</span>
&nbsp;
&gt;&gt; MainClass.<span style="">inner</span>.<span style="">value1</span> = <span style="color: #33f;">9</span>   <span style="color: #228B22;">% one last attempt, that also fails!</span>
MainClass =
    inner: <span style="color: #080;">[</span>1x1 <span style="color: #0000FF;">struct</span><span style="color: #080;">]</span>
&nbsp;
&gt;&gt; MainClass.<span style="">inner</span>
ans =
  <span style="color: #0000FF;">InnerClass</span> with properties:
&nbsp;
    value1: <span style="color: #080;">[</span><span style="color: #080;">]</span>
    value2: <span style="color: #080;">[</span><span style="color: #080;">]</span>
&nbsp;
&gt;&gt; MainClass.<span style="">inner</span>.<span style="">value1</span>
ans =
     <span style="color: #080;">[</span><span style="color: #080;">]</span></pre>
</div>
</div>
<h3 id="bug">Understanding the [buggy?] behavior</h3>
<p>What the heck is going on here? did Matlab's MCOS flip its lid somehow? Well, apparently not. It turns out that all these strange behaviors can be attributed to a single Matlab oddity (I call it a "bug") in its class object system (MCOS) implementation. Understanding this oddity/bug then leads to a very simply workaround.<br />
<span id="more-6100"></span><br />
The underlying problem is that Matlab does not understand <code>MainClass.inner.value1</code> to mean "the <code>value1</code> property of the <code>inner</code> property of the <code>MainClass</code> class". Matlab does understand <code>MainClass.inner</code> to mean "the <code>inner</code> property of the <code>MainClass</code> class", but adding another dereferencing level (<code>.value1</code>) in the same Matlab expression is too complex for MCOS, and it does not properly understand it.<br />
This being the case, Matlab's internal interpreter reverts to the simplistic understanding that <code>MainClass.inner.value1</code> means "the <code>value1</code> field of the struct <code>inner</code>, which is itself a field of the outer struct named <code>MainClass</code>". In fact, this creates a new struct variable named <code>MainClass</code> in our current workspace. Still, due to Matlab's internal precedence rules, the <code>MainClass</code> class overshadows the new variable <code>MainClass</code>, and so when we try to read (as opposed to update) <code>MainClass.inner</code> we are actually referencing the inner reference handle of the <code>MainClass</code> class, rather than the corresponding field in the new struct. The reference handle's <code>value1</code> property remains unmodified because whenever we try to set <code>MainClass.inner.value1</code> to any value, we're just updating the struct variable in the local workspace.<br />
Unfortunately, no run-time warning is issued to alert us of this. However, if we load <i>MainClass.m</i> in the Matlab editor, we get a somewhat-cryptic MLint warning that hints at this:<br />
<center><img decoding="async" title="MLint warning about class object appearing as a struct" src="https://undocumentedmatlab.com/images/MainClass_bug.gif" alt="MLint warning about class object appearing as a struct" width="90%" style="max-width: 642px;"/></center><br />
Confusing? indeed!<br />
(However, refer to the reader comments below, which provide insight into the reasoning of what's going on here, and contend that this is actually the expected behavior. I will let the readers decide for themselves whether they agree or not.)</p>
<h3 id="workaround">The workaround</h3>
<p>Now that we understand the source of all the problems above, the solution is easy: help Matlab's internal interpreter understand that we want to reference a property of the inner object reference. We do this by simply splitting the 3-element construct <code>MainClass.inner.value1</code> into two parts, first storing <code>innerObj = MainClass.inner</code> in a temporary local variable (<code>innerObj</code>), then using it to access the internal <code>innerObj.value1</code> property:</p>
<pre lang='matlab'>
innerObj = MainClass.inner;
innerObj.value1 = 7;
</pre>
<p>Hopefully, in some future Matlab release, MCOS will be smarter than today and automatically handle multi-element MCOS constructs, as well as it currently does for 2-element ones (or multi-element Java/.Net/COM constructs).<br />
Have you ever encountered any other Matlab bug that appears perplexing at first but has a very simple workaround as above? If so, then please share your findings in a comment below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/solving-a-matlab-mcos-bug">Solving a Matlab MCOS bug</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/solving-a-matlab-hang-problem" rel="bookmark" title="Solving a Matlab hang problem">Solving a Matlab hang problem </a> <small>A very common Matlab hang is apparently due to an internal timing problem that can easily be solved. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/solving-a-matlab-bug-by-subclassing" rel="bookmark" title="Solving a MATLAB bug by subclassing">Solving a MATLAB bug by subclassing </a> <small>Matlab's Image Processing Toolbox's impoint function contains an annoying bug that can be fixed using some undocumented properties....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/solving-an-mput-ftp-hang-problem" rel="bookmark" title="Solving an mput (FTP) hang problem">Solving an mput (FTP) hang problem </a> <small>Matlab may hang when using passive FTP commands such as mput and dir. A simple workaround is available to fix this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/types-of-undocumented-matlab-aspects" rel="bookmark" title="Types of undocumented Matlab aspects">Types of undocumented Matlab aspects </a> <small>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/solving-a-matlab-mcos-bug/feed</wfw:commentRss>
			<slash:comments>10</slash:comments>
		
		
			</item>
		<item>
		<title>General-use object copy</title>
		<link>https://undocumentedmatlab.com/articles/general-use-object-copy?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=general-use-object-copy</link>
					<comments>https://undocumentedmatlab.com/articles/general-use-object-copy#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 06 May 2015 13:30:23 +0000</pubDate>
				<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[Internal component]]></category>
		<category><![CDATA[MCOS]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5782</guid>

					<description><![CDATA[<p>Matlab's dual internal serialization/deserialization functions can be used to create duplicates of any object. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/general-use-object-copy">General-use object copy</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/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-cursorbar-object" rel="bookmark" title="Undocumented cursorbar object">Undocumented cursorbar object </a> <small>Matlab's internal undocumented graphics.cursorbar object can be used to present dynamic data-tip cross-hairs...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-private-object-properties" rel="bookmark" title="Accessing private object properties">Accessing private object properties </a> <small>Private properties of Matlab class objects can be accessed (read and write) using some undocumented techniques. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/class-object-tab-completion-and-improper-field-names" rel="bookmark" title="Class object tab completion &amp; improper field names">Class object tab completion &amp; improper field names </a> <small>Tab completions and property access can be customized for user-created Matlab classes. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>When using Matlab objects, either a Matlab class (MCOS) or any other (e.g., Java, COM, C# etc.), it is often useful to create a copy of the original object, complete with all internal property values. This enables modification of the new copy without affecting the original object. This is not important for MCOS value-class objects, since value objects use the COW (<i><a target="_blank" href="/articles/internal-matlab-memory-optimizations">Copy-on-Write</a>/Update</i>, a.k.a. <i>Lazy Copy</i>) and this is handled automatically by the Matlab interpreter when it detects that a change is made to the copy reference. However, it is very important for handle objects, where modifying any property of the copied object also modifies the original object.<br />
Most OOP languages include some sort of a <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Copy_constructor"><i>copy constructor</i></a>, which enables programmers to duplicate a handle/reference object, internal properties included, such that it becomes entirely separate from the original object. Unfortunately, Matlab did not include such a copy constructor until R2011a (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/matlab.mixin.copyable-class.html"><i><b>matlab.mixin.Copyable.copy()</b></i></a>).<br />
On Matlab R2010b and older, as well as on newer releases, we do not have a readily-available solution for handle object copy. Until now, that is.<br />
<span id="more-5782"></span><br />
There are several ways by which we can create such a copy function. We might call the main constructor to create a default object and then override its properties by iterating over the original object&#8217;s properties. This might work in some cases, but not if there is no default constructor for the object, or if there are side-effects to object property modifications. If we wanted to implement a deep (rather than shallow) copy, we&#8217;d need to recursively iterate over all the properties of the internal objects as well.<br />
A simpler solution might be to save the object to a temporary file (<i><b>tempname</b></i>, then load from that file (which creates a copy), and finally delete the temp file. This is nice and clean, but the extra I/O could be relatively slow compared to in-memory processing.<br />
Which leads us to today&#8217;s chosen solution, where we use Matlab&#8217;s builtin functions <i><b>getByteStreamFromArray</b></i> and <i><b>getArrayFromByteStream</b></i>, which I discussed last year as a way to easily <a target="_blank" href="/articles/serializing-deserializing-matlab-data">serialize and deserialize Matlab data</a> of any type. Specifically, <i><b>getArrayFromByteStream</b></i> has the side-effect of creating a duplicate of the serialized data, which is perfect for our needs here (note that these pair of function are only available on R2010b or newer; on R2010a or older we can still serialize via a temp file):</p>
<pre lang='matlab'>
% Copy function - replacement for matlab.mixin.Copyable.copy() to create object copies
function newObj = copy(obj)
    try
        % R2010b or newer - directly in memory (faster)
        objByteArray = getByteStreamFromArray(obj);
        newObj = getArrayFromByteStream(objByteArray);
    catch
        % R2010a or earlier - serialize via temp file (slower)
        fname = [tempname '.mat'];
        save(fname, 'obj');
        newObj = load(fname);
        newObj = newObj.obj;
        delete(fname);
    end
end
</pre>
<p>This function can be placed anywhere on the Matlab path and will work on all recent Matlab releases (including R2010b and older), any type of Matlab data (including value or handle objects, UDD objects, structs, arrays etc.), as well as external objects (Java, C#, COM). In short, it works on anything that can be assigned to a Matlab variable:</p>
<pre lang='matlab'>
obj1 = ... % anything really!
obj2 = obj1.copy();  % alternative #1
obj2 = copy(obj1);   % alternative #2
</pre>
<p>Alternative #1 may look &#8220;nicer&#8221; to a computer scientist, but alternative #2 is preferable because it also handles the case of non-object data (e.g., [] or &#8216;abc&#8217; or <i><b>magic(5)</b></i> or a struct or cell array), whereas alternative #1 would error in such cases.<br />
In any case, using either alternatives, we no longer need to worry about inheriting our MCOS class from <i><b>matlab.mixin.Copyable</b></i>, or backward compatibility with R2010b and older (I may possibly be bashed for this statement, but in my eyes future compatibility is less important than backward compatibility). This is not such a wild edge-case. In fact, I came across the idea for this post last week, when I developed an MCOS project for a consulting client that uses both R2010a and R2012a, and the same code needed to run on both Matlab releases.<br />
Using the serialization functions also solves the case of creating copies for Java/C#/COM objects, which currently have no other solution, except if these objects happen to contain their own copy method.<br />
In summary, using Matlab&#8217;s undocumented builtin serialization functions enables easy implementation of a very efficient (in-memory) copy constructor, which is expected to work across all Matlab types and many releases, without requiring any changes to existing code &#8211; just placing the above <i><b>copy</b></i> function on the Matlab path. This is expected to continue working properly until Matlab decides to remove the serialization functions (which should hopefully never happen, as they are <i>so</i> useful).<br />
Sometimes, the best solutions lie not in sophisticated new features (e.g., <i><b>matlab.mixin.Copyable</b></i>), but by using plain ol&#8217; existing building blocks. There&#8217;s a good lesson to be learned here I think.<br />
p.s. &#8211; I do realize that <i><b>matlab.mixin.Copyable</b></i> provides the nice feature of enabling users to control the copy process, including implementing deep or shallow or selective copy. If that&#8217;s your need and you have R2011a or newer then good for you, go ahead and inherit Copyable. Today&#8217;s post was meant for the regular Joe who doesn&#8217;t need this fancy feature, but does need to support R2010b, and/or a simple way to clone Java/C#/COM objects.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/general-use-object-copy">General-use object copy</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/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/undocumented-cursorbar-object" rel="bookmark" title="Undocumented cursorbar object">Undocumented cursorbar object </a> <small>Matlab's internal undocumented graphics.cursorbar object can be used to present dynamic data-tip cross-hairs...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/accessing-private-object-properties" rel="bookmark" title="Accessing private object properties">Accessing private object properties </a> <small>Private properties of Matlab class objects can be accessed (read and write) using some undocumented techniques. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/class-object-tab-completion-and-improper-field-names" rel="bookmark" title="Class object tab completion &amp; improper field names">Class object tab completion &amp; improper field names </a> <small>Tab completions and property access can be customized for user-created Matlab classes. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/general-use-object-copy/feed</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
		<item>
		<title>Handle object as default class property value</title>
		<link>https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=handle-object-as-default-class-property-value</link>
					<comments>https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 08 Apr 2015 19:39:50 +0000</pubDate>
				<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[MCOS]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5695</guid>

					<description><![CDATA[<p>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value">Handle object as default class property value</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/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/class-object-creation-performance" rel="bookmark" title="Class object creation performance">Class object creation performance </a> <small>Performance aspects of Matlab class object creation are discussed, with specific suggestions. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types-2" rel="bookmark" title="Setting class property types &#8211; take 2">Setting class property types &#8211; take 2 </a> <small>R2016a saw the addition of class property types. However, a better alternative has existed for many years. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types" rel="bookmark" title="Setting class property types">Setting class property types </a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>We all know the benefits of setting default class-property values: it saves coding, increases class readability, improves maintainability and reduces the potential for coding bugs due to uninitialized properties. Basically, we&#8217;re setting default values of the class properties, so that whenever a new instance of this class is created, it will be recreated with these same default property values. This is the behavior in any self-respecting OOP language, and is a well-entrenched paradigm in OOP computing. Simple enough, right?<br />
Well, unfortunately it doesn&#8217;t behave quite this way in Matlab&#8230;<br />
<span id="more-5695"></span></p>
<h3 id="problem">Problem example</h3>
<p>First, define class <code>Internal</code> as follows:</p>
<pre lang='matlab'>
classdef Internal < hgsetget &#038; matlab.mixin.Copyable
    properties
        Value = 0
    end
    methods
        function obj = Internal()
        end
        function set.Value(obj, newValue)
            obj.Value = newValue;
        end
        function str = char(obj)
            str = sprintf('Internal [Value=%s]', mat2str(obj.Value));
        end
        function disp(obj)
            disp(char(obj));
        end
    end
    methods (Static)
        function obj = getDefault()
            obj = Internal();
        end
    end
end
</pre>
<p>Now define class <code>External</code> as follows:</p>
<pre lang='matlab'>
classdef External < hgsetget &#038; matlab.mixin.Copyable
    properties
        MyValue = Internal.getDefault;
    end
    methods
        function obj = External(varargin)
            % empty constructor
        end
        function set.MyValue(obj, newValue)
            obj.MyValue = newValue;
        end
        function str = char(obj)
            str = sprintf('External [MyValue = %s]', char(obj.MyValue));
        end
        function disp(obj)
            disp(char(obj));
        end
    end
end
</pre>
<p>Now run the following (note the highlighted unexpected internal value):</p>
<pre lang='matlab' highlight='12'>
>> clear classes
>> e1 = External
e1 =
External [MyValue = Internal [Value=0]]
>> e1.MyValue.Value = 1
e1 =
External [MyValue = Internal [Value=1]]
>> e2 = External   % This returns a bad value of 1 (should be 0!)
e2 =
External [MyValue = Internal [Value=1]]
>> e1 == e2   % this proves that e1~=e2 (as expected)
ans =
     0
>> Internal.getDefault   % this proves that the default Internal value remains unchanged (as expected)
ans =
Internal [Value=0]
</pre>
<p>Basically, this shows that setting <code>e1.MyValue.Value=1</code> has also affected future class constructions, such that <code>e2=External</code> (which should have created a new handle object with a default property value of 0) now returns the modified value 1.</p>
<h3 id="explanation">How is this possible?</h3>
<p>The answer lies in the fine print of the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/matlab_oop/specifying-properties.html#zmw57dd0e5620">documentation</a>:<br />
&nbsp;&nbsp;&nbsp;&nbsp;<q><i>Evaluation of property default values occurs only when the value is first needed, and only once when MATLAB first initializes the class. MATLAB does not reevaluate the expression each time you create a class instance.</i></q><br />
In other words, when Matlab first loads the <code>External</code> class code into memory (typically upon its first instance creation), it assigns the handle reference to a new <code>Internal</code> instance to the class property. This same handle reference (memory pointer, in a broad sense) is used for all subsequent creations of <code>External</code> class instances. So basically, all instances of <code>External</code> share the same <code>Internal</code> object!<br />
This does not affect properties that are initialized to primitive (non-object) data, nor to <i>value</i> classes (as opposed to <i>handle</i> classes). The reason is that Matlab's built-in COW (<i>copy-on-write</i>) mechanism ensures that we get a new copy of a value class whenever one of its properties is modified. However, this does not happen in handle classes, so modifying <code>Internal</code>'s property in one instance of <code>External</code> also affects the other instances.<br />
So yes, it's fully documented (sort of). But confusing? Counter-intuitive? Unexpected? - you bet!<br />
In recent releases, Matlab increasingly relies on MCOS (Matlab's latest OOP incarnation) for its internal codebase. I venture a guess that if a poll was made among MathWorker developers, the majority (if not vast majority) of them are not aware of this fine detail. Certainly programmers who come from other programming languages would not expect this behavior. This raises a concern that any internal Matlab object that has properties which are handle objects might incur hard-to-trace bugs due to this behavior.</p>
<h3 id="workaround">Workaround and plea for action</h3>
<p>At the moment, the only workaround is to programmatically set the property's default value to a new instance of the handle class in the classes constructor. So, in our case, we would modify <code>External</code>'s constructor as follows:</p>
<pre lang='matlab' highlight='3,9'>
classdef External < hgsetget &#038; matlab.mixin.Copyable
    properties
        MyValue  % no misleading default value here!
    end
    methods
        function obj = External(varargin)
            % non-empty constructor
            obj.MyValue = Internal.getDefault;
        end
...
</pre>
<p>I strongly urge MathWorks to modify this unexpected behavior (and certainly the documentation). I believe that the vast majority of MCOS users would welcome a change to the expected behavior, i.e., create a new <code>Internal</code> object at instance creation time rather than just at class-load time. Moreover, I bet that it would save many internal bugs in Matlab's own code, which is probably by far the largest MCOS codebase worldwide...<br />
I'm the first one to complain about backward incompatibilities, but in this particular case I think that it's not an important concern since users should never rely on this "feature" in their code - it would be bad programming for so many reasons.<br />
Reference: G1308623<br />
<b><u>Addendum April 11, 2015</u></b>: Dave Foti (who heads MCOS development at MathWorks) and Sam Roberts (a former MathWorker) have provided important insight as to the reasons for this confusing behavior (read the comments below). Once we understand it, we can actually use it in interesting ways, to differentiate between class load-time defaults (in the <code>properties</code> section), and class-instantiation defaults (in the constructor). As noted below, MathWorks could probably do a better job of alerting users to the potentially confusion behavior, using either an MLint editor warning, and/or a run-time console warning (preferably both).</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value">Handle object as default class property value</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/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/class-object-creation-performance" rel="bookmark" title="Class object creation performance">Class object creation performance </a> <small>Performance aspects of Matlab class object creation are discussed, with specific suggestions. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types-2" rel="bookmark" title="Setting class property types &#8211; take 2">Setting class property types &#8211; take 2 </a> <small>R2016a saw the addition of class property types. However, a better alternative has existed for many years. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-class-property-types" rel="bookmark" title="Setting class property types">Setting class property types </a> <small>Matlab's class properties have a simple and effective mechanism for setting their type....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value/feed</wfw:commentRss>
			<slash:comments>18</slash:comments>
		
		
			</item>
		<item>
		<title>Simulink Data Dictionary</title>
		<link>https://undocumentedmatlab.com/articles/simulink-data-dictionary?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=simulink-data-dictionary</link>
					<comments>https://undocumentedmatlab.com/articles/simulink-data-dictionary#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 11 Feb 2015 18:00:11 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Donn Shull]]></category>
		<category><![CDATA[MCOS]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Simulink]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5571</guid>

					<description><![CDATA[<p>Simulink contains undocumented public API for access to its data dictionary functionality. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/simulink-data-dictionary">Simulink Data Dictionary</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/improving-simulink-performance" rel="bookmark" title="Improving Simulink performance">Improving Simulink performance </a> <small>Simulink simulation run-time performance can be improved by orders of magnitude by following some simple steps. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/sparse-data-math-info" rel="bookmark" title="Sparse data math info">Sparse data math info </a> <small>Matlab contains multiple libraries for handling sparse data. These can report very detailed internal info. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/controlling-plot-data-tips" rel="bookmark" title="Controlling plot data-tips">Controlling plot data-tips </a> <small>Data-tips are an extremely useful plotting tool that can easily be controlled programmatically....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/draggable-plot-data-tips" rel="bookmark" title="Draggable plot data-tips">Draggable plot data-tips </a> <small>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>Once again I wish to welcome guest blogger <a target="_blank" rel="nofollow" href="http://aetoolbox.com">Donn Shull</a>. Donn has previously written a series of articles on Matlab&#8217;s previous-generation class-object system (<a target="_blank" href="/?s=UDD">UDD</a>). Today Donn explores a little-known yet quite useful aspect of Simulink.</i></p>
<h3 id="Introduction">Introduction</h3>
<p>In 2014, MathWorks introduced the Simulink Data Dictionary. This new feature provides the ability to store <code>Data Types</code>, <code>Parameters</code>, and <code>Signals</code> in database files. This is great news for embedded systems developers who want the flexibility of using data objects and want to avoid using the base workspace with its potential for data corruption.<br />
In its initial implementation, the data dictionary interface is provided by the <a target="_blank" rel="nofollow" href="https://www.mathworks.com/help/simulink/ug/search-and-edit-using-model-explorer.html">Simulink Model Explorer</a>. The GUI interface is clean, intuitive, and easy to use. This interface supports importing and exporting dictionaries to m files and mat files.<br />
Unfortunately, in production code generation environments there is frequently a need to interface this data with external tools such as software specification systems, documentation generators, and calibration tools. MathWorks have not published an API for accessing dictionaries from code, indicating that it may possibly be available in a future release. Today, we will look at some portions of the undocumented API for Simulink Data Dictionaries.<br />
<center><a target="_blank" rel="nofollow" href="https://web.archive.org/web/20150402031355im_/http://www.mathworks.com/help/simulink/ug/importfrombws.png"><img decoding="async" alt="Simulink F14 model using data dictionary" src="https://web.archive.org/web/20150402031355im_/http://www.mathworks.com/help/simulink/ug/importfrombws.png" title="Simulink F14 model using data dictionary" width="100%" style="max-width: 700px;" /></a></center><br />
<span id="more-5571"></span></p>
<h3 id="background">Some background information</h3>
<p>Simulink Data Dictionaries exist as files having a standard file extension of <i>.sldd</i>. Dictionary files can be opened with the <i><b>open</b></i> function, which in turn calls <i><b>opensldd</b></i>. This opens the file and launches the Simulink Model Explorer with the selected dictionary node. When a dictionary is opened, a cached copy is created. While working with a dictionary, changes are made to the cached copy. The dictionary file is only changed when the changes are saved by issuing the relevant command. Until the cached copy is saved, it is possible to view differences between the file and the cached copy, and revert any unwanted changes. The file maintains the date, time, and author of the last saved change, but no information about previous revisions.<br />
From the Model Explorer it is possible to add items to a dictionary from a model, the base workspace, or by creating new items. We can associate a Simulink model with a dictionary by using the model properties dropdown in the Simulink editor.<br />
Using data dictionaries it is possible to tailor a model&#8217;s code generation for different targets, simply by changing the dictionary that is being used.</p>
<h3 id="API">The Simulink Data Dictionary API</h3>
<p>Programmatic access to Simulink Data Dictionaries is provided by the undocumented MCOS package <code>Simulink.dd</code>. We will look at two package functions and a few methods of the <code>Simulink.dd.Connection</code> class. These provide the basic ability to work with dictionaries from within our m code.</p>
<h4 id="create">Creating and Opening Dictionary Files</h4>
<p>Dictionary files are created with the package function <i>create</i>:</p>
<pre lang='matlab'>hDict = Simulink.dd.create(dictionaryFileName);</pre>
<p>Existing dictionary files are opened using the package function <i>open</i>:</p>
<pre lang='matlab'>hDict = Simulink.dd.open(dictionaryFileName);</pre>
<p>In both cases the functions return a handle of type <code>Simulink.dd.Connection</code> to the named dictionary file.</p>
<h4 id="modify">Modifying a Dictionary</h4>
<p>We can use methods of the <code>Simulink.dd.Connection</code> instance to modify an open dictionary. Dictionaries are organized into two sections: The <code>Configurations</code> section contains <code>Simulink.ConfigSet</code> entries, while <code>Parameter</code>, <code>Signal</code>, and <code>DataType</code> items are placed in the <code>Global</code> section. We can get a list of the items in a section using the <i>getChildNames</i> method:</p>
<pre lang='matlab'>childNamesList = hDict.getChildNames(sectionName);</pre>
<p>Adding and removing items from a section are done using the <i>insertEntry</i> and <i>deleteEntry</i> methods, respectively:</p>
<pre lang='matlab'>
hDict.insertEntry(sectionName, entryName, object)
hDict.deleteEntry(sectionName, entryName)
</pre>
<p>Modifying an existing entry is done using the <i>getEntry</i>, and <i>setEntry</i> methods:</p>
<pre lang='matlab'>
workingCopy = hDict.getEntry(sectionName.entryName)
% modify workingCopy
hDict.setEntry(sectionName.entryName, workingCopy)
</pre>
<p>A collection of objects from the base workspace can be added to a dictionary using the <i>importFromBaseWorkspace</i> method:</p>
<pre lang='matlab'>hDict.importFromBaseWorkspace(sectionName, overwriteExisitngObjectsFlag, deleteFromBaseWorkspaceFlag, cellArrayOfNames)</pre>
<p>Additional dictionary manipulations are possible using the <i>evalin</i> and <i>assignin</i> methods:</p>
<pre lang='matlab'>
hDict.evalin(commandString)
hDict.assignin(variableName, variable)
</pre>
<h4 id="close">Closing a Dictionary</h4>
<p>Finalizing a dictionary session is done with the <i>saveChanges</i>, <i>close</i>, and <i>delete</i> methods:</p>
<pre lang='matlab'>
hDict.saveChanges
hDict.close
hDict.delete
</pre>
<h3 id="example">Example: Migrate Single Model to Use Dictionary</h3>
<p>This example is an adaptation of <a target="_blank" rel="nofollow" href="https://www.mathworks.com/help/simulink/ug/migrate-models-to-use-dictionary.html">MathWorks&#8217; interactive example of the same title</a>, using programmatic Matlab commands rather than GUI interactions.</p>
<ol>
<li>Start by using <i><b>load_system</b></i> to open the f14 model. This opens the model and executes the <i>PreLoadFcn</i> callback, which loads design data into the base workspace, without opening the Simulink block diagram editor:
<pre lang='matlab'>load_system('f14');</pre>
</li>
<li>Use the Simulink package function <i>findVars</i> to find the variables used by the model:
<pre lang='matlab'>usedVariables = Simulink.findVars('f14');</pre>
</li>
<li>Next, use the <i>create</i> package function to create and open a new Simulink Data Dictionary:
<pre lang='matlab'>hDict = Simulink.dd.create('f14_data_dictionary.sldd');</pre>
</li>
<li>Attach the newly created dictionary to the model:
<pre lang='matlab'>set_param('f14', 'DataDictionary', 'f14_data_dictionary.sldd');</pre>
</li>
<li>Use one of the API methods to add these variables to the Data Dictionary:
<pre lang='matlab'>
overWrite = true;
deleteFromWorkspace = false;
for n = 1:numel(usedVariables)
    if strcmp(usedVariables(n).Source, 'base workspace')
        hDict.importFromBaseWorkspace(overWrite, deleteFromWorkspace, {usedVariables(n).Name});
    end
end
</pre>
</li>
<li>Save the changes made to the dictionary:
<pre lang='matlab'>hDict.saveChanges;</pre>
</li>
<li>Clean up and we are done:
<pre lang='matlab'>
hDict.close;
hDict.delete;
clear hDict;
</pre>
</li>
</ol>
<h3 id="notes">Final notes</h3>
<p>MathWorks have recognized the value of data dictionaries for a long time. In 2006, MathWorker Tom Erkkinen <a target="_blank" rel="nofollow" href="http://www.eetimes.com/document.asp?doc_id=1272777">published a paper</a> about multitarget modeling using data dictionaries. The <code>Simulink.dd</code> package was added to Matlab in R2011b, and the <code>DataDictionary</code> parameter was added to Simulink models in R2012a. MathWorks have also <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/answers/153367-how-to-eval-expressions-in-simulink-data-dictionaries">indicated</a> that a user API for Simulink Data Dictionaries may be in the works. Until it is released we can make do with the undocumented API.<br />
<b><u>Update March 7, 2015</u></b>: Matlab release R2015a now includes a fully documented <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/slref/simulink.data.dictionary-class.html"><code>Simulink.data.Dictionary</code></a> class, which works in a very similar manner. Users of R2015a or newer should use this new <code>Simulink.data.Dictionary</code> class, while users of previous Matlab releases can use the <code>Simulink.dd</code> class presented in this article.<br />
Have you made some good use of this data-dictionary functionality in your project? If so, please share your experience in a comment below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/simulink-data-dictionary">Simulink Data Dictionary</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/improving-simulink-performance" rel="bookmark" title="Improving Simulink performance">Improving Simulink performance </a> <small>Simulink simulation run-time performance can be improved by orders of magnitude by following some simple steps. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/sparse-data-math-info" rel="bookmark" title="Sparse data math info">Sparse data math info </a> <small>Matlab contains multiple libraries for handling sparse data. These can report very detailed internal info. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/controlling-plot-data-tips" rel="bookmark" title="Controlling plot data-tips">Controlling plot data-tips </a> <small>Data-tips are an extremely useful plotting tool that can easily be controlled programmatically....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/draggable-plot-data-tips" rel="bookmark" title="Draggable plot data-tips">Draggable plot data-tips </a> <small>Matlab's standard plot data-tips can be customized to enable dragging, without being limitted to be adjacent to their data-point. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/simulink-data-dictionary/feed</wfw:commentRss>
			<slash:comments>18</slash:comments>
		
		
			</item>
		<item>
		<title>Class object tab completion &#038; improper field names</title>
		<link>https://undocumentedmatlab.com/articles/class-object-tab-completion-and-improper-field-names?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=class-object-tab-completion-and-improper-field-names</link>
					<comments>https://undocumentedmatlab.com/articles/class-object-tab-completion-and-improper-field-names#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 17 Jul 2014 18:48:29 +0000</pubDate>
				<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[MCOS]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4918</guid>

					<description><![CDATA[<p>Tab completions and property access can be customized for user-created Matlab classes. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/class-object-tab-completion-and-improper-field-names">Class object tab completion &amp; improper field names</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/class-object-creation-performance" rel="bookmark" title="Class object creation performance">Class object creation performance </a> <small>Performance aspects of Matlab class object creation are discussed, with specific suggestions. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/getundoc-get-undocumented-object-properties" rel="bookmark" title="getundoc &#8211; get undocumented object properties">getundoc &#8211; get undocumented object properties </a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>I recently consulted to a very large industrial client. Following a merger/acquisition, the relevant R&#038;D department had two development groups using different technologies: one group uses Matlab, the other does not. My client wanted both groups to use Matlab, something that would naturally please MathWorks.<br />
Unfortunately, it turns out that a technical challenge was preventing this move: the other technology enabled data field names (identifiers) longer than Matlab&#8217;s <i><b>namelengthmax</b></i>=63 characters, and these names also sometimes contained illegal identifier characters, such as spaces or symbols. This prevented an easy code transition, indefinitely delaying the migration to Matlab.</p>
<h3 id="accessing">Accessing improper fieldnames</h3>
<p>I suggested to this client to use Matlab class objects that overloaded the <i><a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/subsref.html">subsref</a>()</i> and <i><a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/subsasgn.html">subsasgn</a>()</i> methods: the long original identifiers would be stored in some internal container (cell array or <i><b>containers.Map</b></i> etc.), and they would be accessed not directly (which would be impossible since they are not valid Matlab identifiers) but via the overloaded methods. Something along the following lines:<br />
<span id="more-4918"></span></p>
<pre lang='matlab'>
classdef ExtendedFieldsClass
    % The internal data implementation is not publicly exposed
    properties (Access = 'protected')
        props = containers.Map;
    end
    methods (Access = 'public', Hidden=true)
        % Overload property assignment
        function obj = subsasgn(obj, subStruct, value)
            if strcmp(subStruct.type,'.')
                try
                    obj.props(subStruct.subs) = value;
                catch
                    error('Could not assign "%s" property value', subStruct.subs);
                end
            else  % '()' or '{}'
                error('not supported');
            end
        end
        % Overload property retrieval (referencing)
        function value = subsref(obj, subStruct)
            if strcmp(subStruct.type,'.')
                try
                    value = obj.props(subStruct.subs);
                catch
                    error('"%s" is not defined as a property', subStruct.subs);
                end
            else  % '()' or '{}'
                error('not supported');
            end
        end
    end
end
</pre>
<p>This works splendidly, as the following snippet shows:</p>
<div class="wp_syntax">
<div class="code">
<pre class="matlab" style="font-family:monospace;"
>&gt;&gt; c = ExtendedFieldsClass
c =
  <span style="color: #0000FF;">ExtendedFieldsClass</span> with no properties.
&nbsp;
&gt;&gt; c.<span style="color: #080;">(</span><span style="color:#A020F0;">' asd f @#$^$%&amp;'</span><span style="color: #080;">)</span> = -<span style="color: #33f;">13.5</span>;  <span style="color: #228B22;">% no error</span>
&nbsp;
&gt;&gt; c.<span style="color: #080;">(</span><span style="color:#A020F0;">' asd f @#$^$%&amp;'</span><span style="color: #080;">)</span>
ans =
                     -<span style="color: #33f;">13.5</span>
&nbsp;
&gt;&gt; c.<span style="color: #080;">(</span><span style="color:#A020F0;">' asd f @#$^$%&amp; xyz'</span><span style="color: #080;">)</span>  <span style="color: #228B22;">% note the extra "xyz"</span>
<span style="color: #FF0000;">Error using ExtendedFieldsClass/subsref (line 27)
" asd f @#$^$%&amp; xyz" is not defined as a property</span></pre>
</div>
</div>
<p>Note how we need to use the () parentheses in order to access the &#8220;properties&#8221; as dynamic fieldnames. We would naturally get an error if we tried to directly access the field:</p>
<div class="wp_syntax">
<div class="code">
<pre class="matlab" style="font-family:monospace;"
>&gt;&gt; c. asd f @#$^$%&
<span style="color: #FF0000;"> c. asd f @#$^$%&
        |
Error: Unexpected MATLAB expression.</span></pre>
</div>
</div>
<h3 id="tab-completion">Tab completion</h3>
<p>So far so good.<br />
The problem is that we would also like to see the defined &#8220;properties&#8221; when in the desktop&#8217;s tab completion. i.e., when I type &#8220;c.&#8221; and then click &lt;tab&gt; in the Matlab command prompt, I&#8217;d like to see the list of defined &#8220;properties&#8221; in a tooltip (in the example above: &#8221; asd f @#$^$%&#038;&#8221;). Instead, I get the message &#8220;No Completions Found.&#8221;:<br />
<center><figure style="width: 200px" class="wp-caption aligncenter"><img decoding="async" alt="Missing tab completion" src="https://undocumentedmatlab.com/images/MCOS_tab_completion1.gif" title="Missing tab completion" width="200" height="40" /><figcaption class="wp-caption-text">Missing tab completion</figcaption></figure></center><br />
I described the hack for <a target="_blank" href="/articles/setting-desktop-tab-completions">desktop tab-completion</a> a few years ago. Unfortunately, that hack only works for functions. We need to find another solution for Matlab class objects.<br />
The solution is to overload the <i>fieldnames()</i> function as well, such that it would return a cell-array of the relevant strings:</p>
<pre lang='matlab' highlight='20-22'>
classdef ExtendedFieldsClass
    % The internal data implementation is not publicly exposed
    properties (Access = 'protected')
        props = containers.Map;
    end
    methods (Access = 'public', Hidden=true)
        % Overload property assignment
        function obj = subsasgn(obj, subStruct, value)
            ...  (as above)
        end
        % Overload property retrieval (referencing)
        function value = subsref(obj, subStruct)
            ...  (as above)
        end
        % Overload fieldnames retrieval
        function names = fieldnames(obj)
            names = sort(obj.props.keys);  % return in sorted order
        end
    end
end
</pre>
<p>When we now run this in the command prompt, we get the expected behavior:<br />
<center><figure style="width: 230px" class="wp-caption aligncenter"><img decoding="async" alt="Working tab completion" src="https://undocumentedmatlab.com/images/MCOS_tab_completion2.gif" title="Working tab completion" width="230" height="100" /><figcaption class="wp-caption-text">Working tab completion</figcaption></figure></center></p>
<h3 id="R2014a">R2014a</h3>
<p>Unfortunately, this works only up to and including Matlab release R2013b. In R2014a, MathWorks made some internal change that prevents overloading the <i>fieldnames</i> function. To be more precise, we can still overload it as above, and it will indeed work if we directly call <i><b>fieldnames</b>(c)</i>, but it no longer has any effect on the tab completion. On R2014a, the tab-completion remains broken and returns &#8220;No Completions Found.&#8221; When this was reported to MathWorks some time ago, the official response was that the previous behavior was considered a &#8220;bug&#8221;, and this was &#8220;fixed&#8221; in R2014a (don&#8217;t bother searching for it in the official bugs parade). Go figure&#8230;<br />
So what do you think I should now do? Remember: this is a large client, who knows how many licenses are at stake. Should I suggest to my client not to switch to Matlab? Or should I suggest that they keep using R2013b across the entire organization and cancel their annual maintenance? Or maybe I should simply tell them to accept the fact that some important functionality should be expected to get broken whenever Matlab is upgraded?<br />
These sort of things just blow me away. Sometimes I feel as if I am swimming against the current, and that&#8217;s frustrating. I admit it doesn&#8217;t happen very often. Then again, I guess if things were straight-forward, nobody would need me to consult them&#8230;<br />
Don&#8217;t mind me &#8211; just blowing off some steam. I&#8217;m allowed to, every now and then, aren&#8217;t I? 🙂<br />
<u><b>Addendum July 21, 2014</b></u>: I found out today that on R2014a+ we can simply overload the <i><b>properties</b></i> method. This is a function that returns the properties of a class, and so it makes perfect sense for a class object&#8217;s tab-completion to use <i><b>properties</b></i> rather than <i><b>fieldnames</b></i>. So I can now indeed see why the past behavior was considered by MathWorks to be a bug that should be fixed. Still, it would have been nice if for backward-compatibility considerations, Matlab (or at least mlint) would have detected the fact that <i><b>fieldnames</b></i> is being overloaded in a user class and warned/alerted regarding the fact that we should now overload <i><b>properties</b></i>. In any case, to be fully backward compatible, simply overload both methods, and make one of them call the other. For example:</p>
<pre lang='matlab'>
        % Overload property names retrieval
        function names = properties(obj)
            names = fieldnames(obj);
        end
</pre>
<p>My client would be quite happy to hear of this new development 🙂</p>
<h3 id="related">Related odds and ends</h3>
<p>Michal Kutil described a mechanism for overloading the <i>methods</i> function, which is also part of the tab-completion tooltip. The problem here is that we cannot simply overload <i>methods</i> in our class, since Matlab calls <i>methods</i> with the class <i>name</i> (not the class <i>object reference</i>) when it wants to determine the relevant methods to display in the tooltip. <a target="_blank" rel="nofollow" href="https://web.archive.org/web/20120103154712/http://www.tim.cz/en/nfaq/matlab-simulink/tab-completion.php">Michal&#8217;s solution</a> was to create a wrapper function that calls the overloaded variant. This wrapper function can then be placed within a @char folder somewhere in the Matlab path. I used a similar trick for my <a target="_blank" href="/articles/function-call-timeline-profiling"><i><b>profile_history</b></i> utility</a> last month.<br />
Related newsgroup posts by Eric Salemi <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/319570">here</a> and <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/283304">here</a>.<br />
Similarly, in order to overload the data-value tooltip (when hovering over the object in the editor), or when displaying the object in the Matlab command prompt, simply overload the <i>disp()</i> function (<a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/15946950/custom-classes-data-tooltips-in-matlab-editor">see related</a>):</p>
<pre lang='matlab'>
        % Overload class object display
        function disp(obj)
            disp([obj.props.keys', obj.props.values']);  % display as a cell-array
        end
</pre>
<p>In a related matter, we can limit the values that a property can accept using the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/slref/matlab.system.stringset-class.html">matlab.system.StringSet</a> class of the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/slref/matlab.system-class.html">matlab.System</a> package, as recently <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/answers/138149-autocomplete-of-properties-for-hgsetget-derived-class#answer_144336">discovered</a> by Oleg Komarov (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/ug/limit-property-values-to-a-finite-set-of-strings-1.html">additional details</a>; <a target="_blank" href="/articles/setting-class-property-types">a different way to constrict property data type</a>):</p>
<pre lang='matlab'>
classdef foo < matlab.System
    properties
        Coordinates
    end
    properties(Hidden,Transient)
        CoordinatesSet = matlab.system.StringSet({'north','south','east','west'});
    end
end
</pre>
<p><center><img decoding="async" alt="restricting Matlab property values" src="http://www.mathworks.com/matlabcentral/answers/uploaded_files/15194/Capture.PNG" title="restricting Matlab property values" width="309" height="129"/></center><br />
This blog will now take a short vacation for a few weeks, due to my <a target="_blank" href="/articles/usa-visit-july-2014">U.S. trip</a>. I will return with some fresh material in August - stay tuned!</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/class-object-tab-completion-and-improper-field-names">Class object tab completion &amp; improper field names</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/class-object-creation-performance" rel="bookmark" title="Class object creation performance">Class object creation performance </a> <small>Performance aspects of Matlab class object creation are discussed, with specific suggestions. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/getundoc-get-undocumented-object-properties" rel="bookmark" title="getundoc &#8211; get undocumented object properties">getundoc &#8211; get undocumented object properties </a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/class-object-tab-completion-and-improper-field-names/feed</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
		<item>
		<title>Accessing private object properties</title>
		<link>https://undocumentedmatlab.com/articles/accessing-private-object-properties?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=accessing-private-object-properties</link>
					<comments>https://undocumentedmatlab.com/articles/accessing-private-object-properties#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 18 Dec 2013 18:00:00 +0000</pubDate>
				<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Mex]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[MCOS]]></category>
		<category><![CDATA[Performance]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4512</guid>

					<description><![CDATA[<p>Private properties of Matlab class objects can be accessed (read and write) using some undocumented techniques. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/accessing-private-object-properties">Accessing private object properties</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/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/getundoc-get-undocumented-object-properties" rel="bookmark" title="getundoc &#8211; get undocumented object properties">getundoc &#8211; get undocumented object properties </a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles" rel="bookmark" title="Adding dynamic properties to graphic handles">Adding dynamic properties to graphic handles </a> <small>It is easy and very useful to attach dynamic properties to Matlab graphics objects in run-time. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Some time ago, I needed to modify a property value of a class object. The problem was that this property was declared as <code><b>private</b></code> and for some reason my client could not modify the originating classdef to make this property accessible.</p>
<h3 id="Problem">Problem definition</h3>
<p>We start with a very simple class definition:<br />
<figure style="width: 200px" class="wp-caption alignright"><img loading="lazy" decoding="async" alt="Inaccessible private property (or is it?)" src="https://undocumentedmatlab.com/images/do_not_enter_sign_200x212.jpg" title="Inaccessible private property (or is it?)" width="200" height="212" /><figcaption class="wp-caption-text">Inaccessible private property (or is it?)</figcaption></figure>   </p>
<pre lang='matlab'>
classdef MyClass
    properties (SetAccess=private)  %GetAccess = public
        y
    end
    properties (Access=private)  %GetAccess = SetAccess = private
        x
    end
    methods
        function obj = MyClass(x,y)  % constructor
            if nargin>0, obj.x = x; end
            if nargin>1, obj.y = y; end
        end
        function result = isPropEqualTo(obj,propName,value)
            result = (obj.(propName)==value);
        end
    end
end
</pre>
<p>The problem is simple: we need to both get and set the value of inaccessible private properties x,y. But following object construction, <code>MyClass</code> enables direct read access only to property y, and write access to neither of its properties:</p>
<pre lang='matlab'>
>> obj = MyClass(3,4)
obj =
  MyClass with properties:
    y: 4
>> obj.x
You cannot get the 'x' property of MyClass.
>> obj.x=5
You cannot set the 'x' property of MyClass.
>> obj.y=5
You cannot set the read-only property 'y' of MyClass.
</pre>
<p>A dead end, would you say? &#8211; Well, it never stopped us before, has it? After all, is it not the raison-d&#8217;être of this blog?<br />
<span id="more-4512"></span></p>
<h3 id="Get">Reading private properties</h3>
<p>Getting the value of x is simple enough when we recall that <a target="_blank" href="/articles/matlab-java-memory-leaks-performance/#struct">calling Matlab&#8217;s <i><b>struct</b></i> function on a class object</a> reveals all its hidden treasures. I wrote about this a couple of years ago, and I&#8217;m not sure how many people realize the power of this undocumented feature:</p>
<pre lang='c'>
>> s = struct(obj)
Warning: Calling STRUCT on an object prevents the object from hiding its implementation details and should thus be avoided.
Use DISP or DISPLAY to see the visible public details of an object. See 'help struct' for more information.
(Type "warning off MATLAB:structOnObject" to suppress this warning.)
s =
    y: 4
    x: 3
</pre>
<p>As the warning mentions, we should not do this often (bad, bad boy!). If we must (I promise I had a good reason, ma!), then we can simply turn off the nagging warning:</p>
<pre lang='matlab'>warning off MATLAB:structOnObject</pre>
<p>We can now read all the private internal properties of the object. Yummy!</p>
<h3 id="Set">Setting private properties</h3>
<p>The natural attempt would now be to update the struct&#8217;s fields with new values. Unfortunately, this does not affect the original class properties, since our struct is merely a copy of the original. Even if our original object is a handle class, the struct would still be a <a target="_blank" href="/articles/class-object-creation-performance/#comment-303863">shallow copy</a> and not a real reference to the object data.<br />
Mex&#8217;s standard <i>mxGetProperty</i> cannot be used on the original object, because <i>mxGetProperty</i> returns a copy of the property (not the original reference &#8211; probably to prevent exactly what I&#8217;m describing here&#8230;), and in any case it can&#8217;t access private properties. <i>mxSetProperty</i> is a dead-end for similar reasons.<br />
The core idea behind the solution is <a target="_blank" href="/articles/internal-matlab-memory-optimizations/">Matlab&#8217;s Copy-on-Write mechanism</a> (COW). This basically means that when our struct is created, the field values actually hold references (pointers) to the original object properties. It is only when trying to <i>modify</i> the struct fields that COW kicks in and a real copy is made. This is done automatically and we do not have any control over it. However, we can use this information to our advantage by retrieving the field references (pointers) <i>before</i> COW has a chance to ruin them. Once we have the reference to the private data, we can <a target="_blank" href="/articles/matlab-mex-in-place-editing/">modify the data in-place using a bit of Mex</a>.<br />
So the trick is to get the reference address (pointer) of <code>s.x</code> and <code>s.y</code>. How do we do that?<br />
We can use another trick here, which is a corollary to the COW mechanism: when we pass <code>s.x</code> into a function, it is not a data copy that is being passed (<i>by value</i>), but rather its pointer (<i>by reference</i>). So we can simply get this pointer in our Mex function and use it to modify the original property value. Easy enough, right?<br />
Not so fast. Don&#8217;t forget that <code>s.x</code> is merely a reference copy of the original property data. If we modify <code>s.x</code>&#8216;s reference we&#8217;re just killing the so-called <i><a target="_blank" rel="nofollow" href="http://www.mk.tu-berlin.de/Members/Benjamin/mex_sharedArrays">cross-link of the shared-array</a></i>. What we need to do (more or less) is to traverse this cross-link back to its source, to get the <i>real</i> reference to the data.<br />
Sounds complicated? Well, it is a bit. Luckily, Mex guru James (Jim) Tursa comes to the rescue with his <i><a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/30672-mxgetpropertyptr-c-mex-function">mxGetPropertyPtr</a></i> function on the File Exchange, which does all that for us. Once we have it compiled (the utility automatically Mex-compiles itself on first use), we can use it as follows (note the highlighted line using <i>mxGetPropertyPtr</i>):</p>
<pre lang='c' highlight='20'>
/* Place in mxMySetProperty.c and mex-compile*/
#include "mex.h"
#include "mxGetPropertyPtr.c"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    mxArray *x;
    register double *xpr;
    int buflen;
    char *propName = "x";
    double newValue = -3.14159265358979;
    if ( nrhs > 1 ) {
        /* Get the specified property name (or "x" if not specified) */
        buflen = mxGetNumberOfElements(prhs[1]) + 1;
        propName = mxCalloc(buflen, sizeof(char));
        mxGetString(prhs[1], propName, buflen);
    }
    /* Get the pointer to the original property data */
    x = mxGetPropertyPtr(prhs[0],0,propName);
    if ( !x ) {
        mexErrMsgTxt("Failed to get pointer to property.");
    }
    /* Display the existing property value */
    xpr = mxGetPr(x);
    mexPrintf("existing value of property %s = %f\n", propName, *xpr);
    /* Update the property with the new value */
    if ( nrhs > 2 ) {
        /* Get the specified new value (or -pi if not specified) */
        double *pr = mxGetPr(prhs[2]);
        newValue = *pr;
    }
    mexPrintf("setting value of property %s to %f\n", propName, newValue);
    *xpr = newValue;
}
</pre>
<p>Naturally, this simplistic Mex function should also be made to accept non-scalar values. This is left as an exercise to the reader.<br />
The usage in Matlab of this <i>mxMySetProperty</i> function is super simple:</p>
<pre lang='matlab'>
% Update obj.x from 3 => pi/2
>> mxMySetProperty(s,'x',pi/2);
existing value of property x = 3.000000
setting value of property x to 1.570796
% Update obj.y from 4 => -5
>> mxMySetProperty(s,'y',-5);  % here we can also use obj instead of s since obj.y is accessible
existing value of property y = 4.000000
setting value of property y to -5.000000
% Check that the struct copy has been updated correctly
>> s
s =
    y: -5
    x: 1.5707963267949
% Check that the original object's private properties have been updated correctly
>> obj
obj =
  MyClass with properties:
    y: -5
>> obj.isPropEqualTo('x',pi/2)
ans =
    1     % ==true
</pre>
<p>Jim Tursa has promised to supply a <i>mxSetPropertyPtr</i> variant of his <i>mxGetPropertyPtr</i> for the past two years (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/30672-mxgetpropertyptr-c-mex-function">1</a>,<a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/answers/4682#answer_6618">2</a>,<a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/answers/25247#comment_56121">3</a>,<a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/answers/79046">4</a>). It will surely be more robust than my simplistic <i>mxMySetProperty</i> function, so I look forward to finally seeing it on FEX!</p>
<h3 id="Conclusion">Conclusion</h3>
<p>With some dirty tricks and undocumented hacks, we can both get and set private-access object properties. Please don&#8217;t do this unless you have a really good reason (such as a customer breathing down your neck, who doesn&#8217;t give a fig that his properties were declared private&#8230;).<br />
The mechanism shown above can also be used to improve performance when updating public object properties, since it updates the data in-place rather than create a copy. This could be significant when the property size is very large (multi-MB), since it avoids unnecessary memory allocation and deallocation. You might think that with public properties we could use the standard <i>mxGetProperty</i> for this, but as I said above this function apparently returns a copy of the data, not a direct reference. Also note that last month I discussed additional <a target="_blank" href="/articles/performance-accessing-handle-properties/">performance aspects of accessing object properties</a>.<br />
This blog will now take a short break for the holidays. I hope you had a good ride this year, see you again on the other side of 2013.<br />
Merry Christmas and happy New-Year everybody! </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/accessing-private-object-properties">Accessing private object properties</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/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/getundoc-get-undocumented-object-properties" rel="bookmark" title="getundoc &#8211; get undocumented object properties">getundoc &#8211; get undocumented object properties </a> <small>getundoc is a very simple utility that displays the hidden (undocumented) properties of a specified handle object....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles" rel="bookmark" title="Adding dynamic properties to graphic handles">Adding dynamic properties to graphic handles </a> <small>It is easy and very useful to attach dynamic properties to Matlab graphics objects in run-time. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/accessing-private-object-properties/feed</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>Class object creation performance</title>
		<link>https://undocumentedmatlab.com/articles/class-object-creation-performance?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=class-object-creation-performance</link>
					<comments>https://undocumentedmatlab.com/articles/class-object-creation-performance#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 11 Dec 2013 16:50:14 +0000</pubDate>
				<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[MCOS]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4496</guid>

					<description><![CDATA[<p>Performance aspects of Matlab class object creation are discussed, with specific suggestions. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/class-object-creation-performance">Class object creation 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/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/class-object-tab-completion-and-improper-field-names" rel="bookmark" title="Class object tab completion &amp; improper field names">Class object tab completion &amp; improper field names </a> <small>Tab completions and property access can be customized for user-created Matlab classes. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/general-use-object-copy" rel="bookmark" title="General-use object copy">General-use object copy </a> <small>Matlab's dual internal serialization/deserialization functions can be used to create duplicates of any object. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/object-oriented-programming.html">Matlab&#8217;s Class Object System</a> (MCOS) is a powerful way to develop maintainable, modular, reusable code using a modern Object Oriented Programming (OOP) paradigm. Unfortunately, using OOP in Matlab carries some performance penalties that need to be considered when deciding whether to code in the new paradigm or keep using the older, simpler procedural paradigm. A major resource in this regard is a detailed <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/loren/2012/03/26/considering-performance-in-object-oriented-matlab-code/">post from 2012</a> by Dave Foti, who heads MCOS development at MathWorks.<br />
As Dave pointed out, the importance of MCOS&#8217;s overheads only comes into play when our program uses many class objects and calls many short-duration methods. In the majority of cases, this is actually not the case: Our performance bottlenecks are normally I/O, GUI, memory and processing algorithm – not object manipulation and function-call overheads. Unfortunately, Dave&#8217;s article left out many ideas for improving MCOS performance in those cases where it does matter.<br />
Today&#8217;s article will expand on the sub-topic of MCOS object creation. While it does not directly rely on any undocumented aspect, I have also not seen it directly explained in the official docs. So consider this to be the missing doc page&#8230;<br />
<span id="more-4496"></span></p>
<h3 id="superclasses">Constructor chaining</h3>
<p>In his article, Dave&#8217;s main suggestion for improving object creation performance was to reduce the number of super-classes. When creating class objects, each creation needs to chain the default values and constructors of its ancestor super-classes. The more superclasses we have, the more modular our code can become, but this makes object creation slightly slower. The effect is typically on the order of a few millisecs or less, so unless we have a very long super-class chain or are bulk-creating numerous objects, this has little impact on the overall program performance.</p>
<h3 id="pooling">Object pooling</h3>
<p>Objects are typically created at the beginning of a program and used throughout it. In such cases, we only pay the small performance penalty once. In cases where objects are constantly being destroyed and created throughout the program&#8217;s duration, consider using <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Object_pool_pattern">object pooling</a> to reuse existing objects. The basic idea is to create a set of ready-to-use objects at the beginning of the program. A static (<a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton</a>) dispatcher (<a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Factory_method_pattern">factory</a>) object would create this pool of objects in its constructor, possibly with a few new objects ready for use. The factory&#8217;s only public interface would be public <i>pull/recycle</i> methods to retrieve and return objects from/to the pool. The program would have no access to the objects pool (except via these public methods), since the pool is stored in the factory object&#8217;s private data.<br />
The <i>pull</i> method would create new objects only when asked to retrieve objects from an empty pool; otherwise it would simply return a reference to one of the unused pool objects (which need to be <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/matlab_oop/comparing-handle-and-value-classes.html">handle class objects</a> to be reference-able). The <i>recycle</i> method will be used to return objects to the pool, once they have been used, to enable these objects to be reused later (via subsequent <i>pull</i>s).<br />
Object pooling entails programming overheads that only make sense when a large number of short-lived objects are constantly being created and destroyed, or when object creation is especially expensive. It is often used in databases (connection pooling), since programs often connect to a database numerous times for short-lived SQL queries. Similar ideas can be found in GUI and I/O programming.<br />
Here is a simple implementation of such a system. The singleton factory class is <code>Widgets</code> and it holds a pool of reusable <code>Widget</code> objects:</p>
<pre lang='matlab'>
% Manage a persistent, global, singleton list of Widget objects
classdef Widgets < handle
    properties (Access=private)
        UnusedWidgets@Widget   % only accept elements of type Widget
    end
    methods (Access=private)
        % Guard the constructor against external invocation.
        % We only want to allow a single instance of this class
        % This is ensured by calling the constructor from the static (non-class) getInstance() function
        function obj = Widgets()
            % Initialize an initial set of Widget objects
            for idx = 1 : 5
                try
                    obj.UnusedWidgets(idx) = Widget;
                catch
                    obj.UnusedWidgets = Widget;  % case of idx==1
                end
            end
        end
    end
    methods (Static)  % Access=public
        % Get a reference to an unused or new widget
        function widget = pull()
            obj = getInstance();
            try
                % Try to return a widget from the list of UnusedWidgets
                widget = obj.UnusedWidgets(end);
                obj.UnusedWidgets(end) = [];  % remove from list
            catch
                widget = Widget;  % create a new Widget object
            end
        end
        % Return a widget to the unused pool, once we are done with it
        function recycle(widget)
            obj = getInstance();
            obj.UnusedWidgets(end+1) = widget;
        end
    end
end
% Concrete singleton implementation
% Note: this is deliberately placed *outside* the class, so that it is not accessible to the user
function obj = getInstance()
    persistent uniqueInstance
    if isempty(uniqueInstance)
        obj = Widgets();
        uniqueInstance = obj;
    else
        obj = uniqueInstance;
    end
end
</pre>
<p>We can access and use the <code>Widgets</code> object pool as follows:</p>
<pre lang='matlab'>
% Retrieve a Widget object instance from the pool of objects, or create a new instance as needed
widget = Widgets.pull();
% Now use this widget object until we're done with it
% Return the object to the pool, for possible later reuse
Widgets.recycle(widget);
</pre>
<p><i>Credit: inspired by Bobby Nedelkovski&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/24911-design-pattern-singleton-creational">Singleton class implementation</a></i></p>
<h3 id="handle">Handle vs. value class objects</h3>
<p>Another consideration when designing classes is that while handle classes are slightly slower to create (due to multiple super-class overheads), they are typically much faster to use. The reason is that handle classes are passed to functions by reference, whereas value classes are passes by value. Whenever we modify a handle class property within a function, we directly manipulate the relevant property memory. On the other hand, when we manipulate a value class property, a copy of the class needs to be created and then the modified class needs to be copied back to the original object&#8217;s memory (using <a target="_blank" href="/articles/internal-matlab-memory-optimizations/">Matlab&#8217;s Copy-on-Write mechanism</a>). Since we cannot normally anticipate all usage patterns of a class when we create it, I suggest to create any new user class as handle class, unless there is a specific good reason to make it a value class. All it takes is to add the <i><b>handle</b></i> (or <i><b>hgsetget</b></i>) inheritance to the class definition:</p>
<pre lang='matlab'>classdef MyClass < handle</pre>
<h3 id="preallocation">Preallocation</h3>
<p>When implicit expansion of class-object arrays takes place, an <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/matlab_oop/creating-object-arrays.html#bru6o00">abbreviated version of object instance creation</a> takes place, which bypasses the constructor calls and just copies the instance properties. For example, <code>array(9)=Widget</code> creates an array of 9 separate Widget objects, but the <code>Widget</code> constructor is only called for <code>array(1)</code> and <code>array(9)</code>; <code>array(1)</code> is then expanded (copied-over) to the remaining objects <code>array(2:8)</code>.<br />
When preallocating, ensure that you are using the maximal expected array size. There is no point in preallocating an empty array or an array having a smaller size than the expected maximum, since dynamic memory reallocation will automatically kick-in within the processing-loop. For this reason, avoid using the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/matlab_oop/creating-object-arrays.html#brd4nrh"><i>empty()</i> method</a> of class objects to preallocate - use <i><b>repmat</b></i> instead (<a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/2510427/how-to-preallocate-an-array-of-class-in-matlab">ref</a>).<br />
When using <i><b>repmat</b></i> to replicate class objects, always be careful to note whether you are replicating the object itself (this happens if your class does NOT derive from <i><b>handle</b></i>) or its reference handle (which happens if you derive the class from <i><b>handle</b></i>). If you are replicating objects, then you can safely edit any of their properties independently of each other; but if you replicate references, you are merely using multiple copies of the same reference, so that modifying referenced object #1 will also automatically affect all the other referenced objects. This may or may not be suitable for your particular program requirements, so be careful to check carefully. If you actually need to use independent object copies, you will need to call the class constructor multiple times, once for each new independent object (<a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/591495/matlab-preallocate-a-non-numeric-vector#591788">ref</a>).<br />
Preallocation of class objects (class instances) can be used not just as a means of avoiding dynamic allocation, but also as a means of controlling the time of object initialization. Object initialization, typically done in the class’s constructor method, could be lengthy (depending on your specific application). By preallocating the object, we can control the exact timing in which this initialization occurs, possibly at such a time that is less time-critical in the regular application time-flow. This relates to the concepts of <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Lazy_initialization">lazy initialization</a>, a special case of <a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Lazy_evaluation">deferred (or demand-driven) evaluation</a>.<br />
For additional aspects of preallocation performance, refer to my <a target="_blank" href="/articles/preallocation-performance/">article from last year</a>, which discusses class objects only briefly, but expands on the other data types.</p>
<h3 id="training">London training course - March 2014</h3>
<p>If you are interested in improving your Matlab application's performance and your Matlab programming skills in general, join my upcoming <a target="_blank" href="/articles/sprintfc-undocumented-helper-function/#training">Advanced Matlab Programming course</a> in London, March 2014 – an intensive 2 day course on best practices, preparing professional reports and performance tuning. I guarantee that following this course your Matlab programming skills will be at a higher level.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/class-object-creation-performance">Class object creation 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/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/class-object-tab-completion-and-improper-field-names" rel="bookmark" title="Class object tab completion &amp; improper field names">Class object tab completion &amp; improper field names </a> <small>Tab completions and property access can be customized for user-created Matlab classes. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/creating-a-simple-udd-class" rel="bookmark" title="Creating a simple UDD class">Creating a simple UDD class </a> <small>This article explains how to create and test custom UDD packages, classes and objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/general-use-object-copy" rel="bookmark" title="General-use object copy">General-use object copy </a> <small>Matlab's dual internal serialization/deserialization functions can be used to create duplicates of any object. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/class-object-creation-performance/feed</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>Performance: accessing handle properties</title>
		<link>https://undocumentedmatlab.com/articles/performance-accessing-handle-properties?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=performance-accessing-handle-properties</link>
					<comments>https://undocumentedmatlab.com/articles/performance-accessing-handle-properties#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 20 Nov 2013 18:00:45 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[HG2]]></category>
		<category><![CDATA[MCOS]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4403</guid>

					<description><![CDATA[<p>Handle object property access (get/set) performance can be significantly improved using dot-notation. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/performance-accessing-handle-properties">Performance: accessing handle properties</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/accessing-private-object-properties" rel="bookmark" title="Accessing private object properties">Accessing private object properties </a> <small>Private properties of Matlab class objects can be accessed (read and write) using some undocumented techniques. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties" rel="bookmark" title="Displaying hidden handle properties">Displaying hidden handle properties </a> <small>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/adding-custom-properties-to-gui-objects" rel="bookmark" title="Adding custom properties to GUI objects">Adding custom properties to GUI objects </a> <small>It is very easy to add custom user-defined properties and methods to GUI handles and Java references in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-graphics-behavior" rel="bookmark" title="Handle Graphics Behavior">Handle Graphics Behavior </a> <small>HG behaviors are an important aspect of Matlab graphics that enable custom control of handle functionality. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<h3 id="HG">Graphic handle properties</h3>
<p>There are several ways to access (read or update) Handle Graphics object properties. The simplest (and documented) way is to use the built-in <i><b>get</b></i> and <i><b>set</b></i> functions on the HG object’s handle. However, it is not the fastest: a significant speedup is possible (see below).<br />
Accessing individual properties is so fast that this speedup may not seem important. Individual properties are accessed in tens or hundreds of microseconds, which is a very short time for most Matlab programs. Indeed, if our application seldom accesses properties, it is probably not worth the effort to optimize this particular aspect of the program:</p>
<pre lang='matlab'>
% Individual property access is extremely fast:
hFig = figure;
tic, figName = get(hFig,'name'); toc  % Elapsed time is 0.000229 seconds.
tic, set(hFig,'name','testing'); toc  % Elapsed time is 0.000270 seconds.
</pre>
<p>But if we have thousands of reads and/or updates, this could possibly become an important factor (<i><b>drawnow</b></i> calls are intentionally omitted to illustrate the effect):</p>
<pre lang='matlab'>
% Using the standard set() function
tic, for idx=1:10000, set(hFig,'name','testing'); end, toc  % Elapsed time is 0.229772 seconds.
% Using the HG handle() wrapper is about 25% faster (or 1.3x speedup):
tic
hFig = handle(hFig);
for idx=1:10000, set(hFig,'name','testing'); end
toc  % Elapsed time is 0.170205 seconds.
% Using the HG handle() wrapper with dot notation is even faster (65% faster, or 2.7x speedup):
tic
hFig = handle(hFig);
for idx=1:10000, hFig.name='testing'; end
toc  % Elapsed time is 0.083762 seconds.
</pre>
<p><span id="more-4403"></span><br />
Similar results occur when trying to <i><b>get</b>()</i> a property value:</p>
<pre lang='matlab'>
% Using the standard set() function
tic, for idx=1:10000, s=get(hFig,'name'); end, toc   % Elapsed time is 0.140865 seconds.
% Using the HG handle() wrapper is about 25% faster (or 1.3x speedup):
tic, hFig=handle(hFig); for idx=1:10000, s=get(hFig,'name'); end, toc  % Elapsed time is 0.108543 seconds.
% Using the HG handle() wrapper with dot notation is even faster (62% faster, or 2.6x speedup):
tic, hFig=handle(hFig); for idx=1:10000, s=hFig.name; end, toc   % Elapsed time is 0.053423 seconds.
</pre>
<p>We learn from this that using the HG <i><b>handle</b>()</i> wrapper function is useful for improving performance. This has the benefit of improving our code performance with minimal changes to our code, by simply updating our handle to be a <i><b>handle</b>()</i> wrapper:</p>
<pre lang='matlab'>hFig = handle(hFig);</pre>
<p>Using the <i><b>handle</b></i>’d handle enables further performance benefits if we use the dot notation (<code>handle.propertyName</code>), rather than use the familiar <i><b>get/set</b></i> functions.<br />
Note that both the <i><b>handle</b></i> function and its beneficial effects on performance are undocumented.</p>
<h3 id="Java">Java reference properties</h3>
<p>The same conclusions also hold true for Java objects, where it turns out that using <i><b>handle</b>()</i> and the simple dot notation is 2-6 times as fast as using the Java <i>set&lt;PropName&gt;</i> and <i>get&lt;PropName&gt;</i> functions, due to Matlab-Java interface aspects:</p>
<pre lang='matlab'>
jb = javax.swing.JButton;
% Using the standard set() function
tic, for idx=1:10000, set(jb,'Text','testing'); end, toc  % Elapsed time is 0.278516 seconds.
% Using the HG handle() wrapper is about 35% faster (or 1.6x speedup):
jhb = handle(jb);
tic, for idx=1:10000, set(jhb,'Text','testing'); end, toc   % Elapsed time is 0.175018 seconds.
% Using the HG handle() wrapper with dot notation is even faster (65% faster, or 2.8x speedup):
tic, for idx=1:10000, jhb.text='testing'; end, toc  % Elapsed time is 0.100239 seconds.
% Using the Java setText() function, is actually slower (faster with the handle() wrapper, but still slower than dot-notation):
tic, for idx=1:10000, jb.setText('testing'); end, toc  % Elapsed time is 0.587543 seconds.
tic, for idx=1:10000, jhb.setText('testing'); end, toc  % Elapsed time is 0.201635 seconds.
</pre>
<p>The same holds true also for retrieving property values via the <i><b>get</b></i> function.</p>
<h3 id="Class">User handle class properties</h3>
<p>Exactly the same conclusions also apply to non-graphical user classes that derive from the base <i><b>handle</b></i> class regarding property access. In this case, we derive the <i><b>hgsetget</b></i> built-in class, which provides a <i><b>handle</b></i> class with the standard <i><b>get/set</b></i> functions. Note that this is documented &#8211; it is only the performance implications that are undocumented in this case.<br />
We first create a simple class for testing:</p>
<pre lang='matlab'>
% Define a simple handle class
classdef TestClass < hgsetget
    properties
        name
    end
end
</pre>
<p>Now let's test both sides of the property access (get/set) - first let's set the property value:</p>
<pre lang='matlab'>
obj = TestClass;
% Using the standard set() function
tic, for idx=1:10000, set(obj,'name','testing'); end, toc  % Elapsed time is 0.138276 seconds.
% Using class.propName notation - 72x faster!
tic, for idx=1:10000, obj.name='testing'; end, toc  % Elapsed time is 0.001906 seconds.
</pre>
<p>And similarly for retrieving a property value:</p>
<pre lang='matlab'>
% Using the standard set() function
tic, for idx=1:10000, a=get(obj,'name'); end, toc  % Elapsed time is 0.105168 seconds.
% Using class.propName notation - 6.5x faster
tic, for idx=1:10000, a=obj.name; end, toc  % Elapsed time is 0.016179 seconds.
</pre>
<h3 id="Conclusions">Conclusions</h3>
<p>The general conclusion is that we should always strive to use the dot notation (<code>handle.propertyName</code>), rather than use the familiar <i><b>get/set</b></i> functions, in performance hotspots. Naturally, doing this in non-hotspot locations is futile, since accessing individual properties is relatively fast.<br />
In the upcoming <a target="_blank" href="/articles/hg2-update/">HG2</a>, when all of Matlab&#8217;s GUI and graphic objects will use Matlab classes, this conclusion will be more important than ever. Initial tests on the HG2 alpha (that <a target="_blank" href="/articles/hg2-update/#testing">anyone can access</a>) show that they hold true for HG2 just as they do in the current HG1.<br />
The <i><b>handle</b>()</i> function wrapper produces a <a target="_blank" href="/?s=UDD">UDD</a> (<i><b>schema</b></i>) object, so while I have not specifically tested non-HG <i><b>schema</b></i> objects, I would be very surprised if the conclusions do not hold true for all UDD objects in general.<br />
I have also not [yet] tested other types of handles (ActiveX/COM, Dot-Net etc.) but again, I would be very surprised if the conclusions would be any different.<br />
If this performance tip has piqued your interest, then you might be interested in the several hundred other tips in my upcoming book &#8220;<b>MATLAB Performance Tuning</b>&#8221; (CRC Press, 2014). I&#8217;ll post a note on this blog letting everyone know when it&#8217;s officially available. In the meantime, enjoy my other <a target="_blank" href="/articles/tag/Performance/">performance-related articles</a> &#8211; there are already several dozen of them by now, and the list will continue to grow&#8230;<br />
<i>Editorial note: In the past month I&#8217;ve gone to quite a lot of effort to improve the performance of this website. Most users should now see pages loading about twice as fast as one month ago. The effect should be especially noticeable on mobile devices connected over mobile, which is <a target="_blank" rel="nofollow" href="https://www.youtube.com/watch?v=7gtf47D_bu0">much slower</a> than wifi/cable. I still have a few additional tweak ideas, so I expect performance to slightly improve even further in the upcoming weeks. Enjoy reading!</i></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/performance-accessing-handle-properties">Performance: accessing handle properties</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/accessing-private-object-properties" rel="bookmark" title="Accessing private object properties">Accessing private object properties </a> <small>Private properties of Matlab class objects can be accessed (read and write) using some undocumented techniques. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/displaying-hidden-handle-properties" rel="bookmark" title="Displaying hidden handle properties">Displaying hidden handle properties </a> <small>I present two ways of checking undocumented hidden properties in Matlab Handle Graphics (HG) handles...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/adding-custom-properties-to-gui-objects" rel="bookmark" title="Adding custom properties to GUI objects">Adding custom properties to GUI objects </a> <small>It is very easy to add custom user-defined properties and methods to GUI handles and Java references in Matlab. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-graphics-behavior" rel="bookmark" title="Handle Graphics Behavior">Handle Graphics Behavior </a> <small>HG behaviors are an important aspect of Matlab graphics that enable custom control of handle functionality. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/performance-accessing-handle-properties/feed</wfw:commentRss>
			<slash:comments>13</slash:comments>
		
		
			</item>
		<item>
		<title>Setting class property types</title>
		<link>https://undocumentedmatlab.com/articles/setting-class-property-types?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=setting-class-property-types</link>
					<comments>https://undocumentedmatlab.com/articles/setting-class-property-types#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 18 Apr 2013 14:12:06 +0000</pubDate>
				<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[MCOS]]></category>
		<category><![CDATA[Object oriented]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[schema.prop]]></category>
		<category><![CDATA[UDD]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3725</guid>

					<description><![CDATA[<p>Matlab's class properties have a simple and effective mechanism for setting their type.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/setting-class-property-types">Setting class property types</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/setting-class-property-types-2" rel="bookmark" title="Setting class property types &#8211; take 2">Setting class property types &#8211; take 2 </a> <small>R2016a saw the addition of class property types. However, a better alternative has existed for many years. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/types-of-undocumented-matlab-aspects" rel="bookmark" title="Types of undocumented Matlab aspects">Types of undocumented Matlab aspects </a> <small>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>When I wrote about the <a target="_blank" href="/articles/undocumented-classdef-attributes/">undocumented aspects of classdef properties</a> half a year ago, I did not expect to learn of another major undocumented aspect in Matlab&#8217;s class-object system. last month I discovered the additional undocumented classdef Description and DetailedDescription attributes, and updated that article accordingly. But a few days ago I was pleasantly surprised to read Amro&#8217;s <a target="_blank" href="/articles/undocumented-classdef-attributes/#comment-189056">comment</a> about an entirely new and undocumented aspect of Matlab MCOS classes.</p>
<p><a target="_blank" rel="nofollow" href="http://stackoverflow.com/users/97160/amro">Amro</a> is a top contributor on StackOverflow, where he frequently answers questions before I even get any subscription notification about them&#8230; His answers are generally characterized by a deep technical understanding of Matlab, and I&#8217;ve learned quite a lot from him in the past few years. This time was no different.</p>
<p>In a nutshell, Amro found an undocumented way to specify a class object property&#8217;s type, in such a way that would prevent accidental setting to an incompatible value. For example, if we have a class with properties <b>Width</b> and <b>Height</b>, we probably want to restrict their possible values to numbers, to prevent setting a string or struct value.</p>
<p>In UDD classes, we can do this easily by setting the property&#8217;s <b>DataType</b> meta-property. An easy way to do this is by setting the second argument of the <a target="_blank" href="/articles/creating-a-simple-udd-class/"><i><b>schema.prop</b></i> function</a>. A detailed explanation was provided <a target="_blank" href="/articles/udd-properties/">here</a>.</p>
<p>We can still do this today, since UDD classes are still supported, side-by-side with the newer MCOS classes. Unfortunately, MCOS does not provide a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/matlab_oop/defining-properties.html">documented</a> way of specifying the property type as in UDD.</p>
<p>One simple way to prevent unintentional MCOS property updates is to <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/matlab_oop/implementing-a-set-get-interface-for-properties.html">override the property&#8217;s <i><b>set</b></i> method</a>. In fact, this was the <a target="_blank" rel="nofollow" href="http://stackoverflow.com/a/7192964/233829">solution</a> of Jonas, another StackOverflow heavyweight:</p>
<pre lang='matlab'>
classdef myClass
   properties
      myProperty = uint16(23); %# specify default value using correct type
   end
   methods
      function obj = set.myProperty(obj,val)
         if ~isa(val,'uint16')
            error('only uint16 values allowed')
         end
         %# assign the value
         obj.myProperty = val;
      end
   end
end
</pre>
<p>But it turns out that there&#8217;s a much cleaner and simpler solution, <a target="_blank" rel="nofollow" href="http://stackoverflow.com/a/15992558/233829">provided</a> by Amro:</p>
<pre lang='matlab'>
classdef Packet
    properties
        HeaderLength@uint16
        PayloadLength@uint16 = uint16(0);
        PacketType@char
    end
end
</pre>
<p><span id="more-3725"></span><br />
As Amro notes, if you try to set a property with the wrong type, you get an error:</p>
<div class="wp_syntax">
<div class="code">
<pre class="matlab" style="font-family:monospace;">&gt;&gt; p = Packet;
&gt;&gt; p.<span style="">PacketType</span> = <span style="color:#A020F0;">'tcp'</span>;  <span style="color: #228B22;">% ok</span>
&gt;&gt; p.<span style="">HeaderLength</span> = <span style="color: #33f;">100</span>;  <span style="color: #228B22;">% not ok - should be a uint16</span>
<span style="color: #FF0000;">While setting the 'HeaderLength' property of Packet:
Value must be 'uint16'</span>.</pre>
</div>
</div>
<p>This syntax apparently supports all primitive types (<i><b>char, int32, double, struct, cell</b></i> etc.), in addition to any user-defined ones (just use any class name).<br />
Note that setting the type as above seems to override any <i><b>set</b></i> method that may have been specified for the property.</p>
<p>Amro came across this syntax in an internal class in R2013a (<i>toolboxdir(&#8216;matlab&#8217;)/graphics/+graphics/+internal/+figfile/@FigFile/FigFile.m</i>), but it also worked in R2012a, and probably older versions as well&#8230;</p>
<p>I admit there&#8217;s not much original work here by me &#8211; it&#8217;s basically all by Amro (and Donn Shull for the UDD part). But I thought it&#8217;s important enough to bring to the attention of the community.</p>
<p>I love to discover such undocumented treasures by digging in Matlab&#8217;s function. If you ever discover other such buried treasures, please do let me know by email or a comment.</p>
<hr />
<p><b><u>Addendum June 21, 2013</u></b>: As Sebastian Hölz mentioned in his <a href="/articles/setting-class-property-types/#comment-215669">comment</a> below, the general syntax appears to be:</p>
<pre lang='matlab'>
properties
   propName@className dimensionType = initialValue
end
</pre>
<p>where <code>className</code>, <code>dimensionType</code> and <code>initialValue</code> are optional elements:</p>
<ul>
<li><code>className</code> can be any Matlab class/type, such as <code>double</code>, <code>single</code>, or <code>UserClass</code></li>
<li><code>dimensionType</code> can be one of the following terms: <code>scalar</code>, <code>vector</code>, or <code>matrix</code></li>
<li>the property may also be initiated with an <code>initialValue</code> (otherwise it receives a default value, depending on the property class)</li>
</ul>
<hr />
<p><b><u>Addendum August 12, 2014</u></b>: In a related matter, we can limit the values that a property can accept using the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/slref/matlab.system.stringset-class.html">matlab.system.StringSet</a> class of the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/slref/matlab.system-class.html">matlab.System</a> package, as recently <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/answers/138149-autocomplete-of-properties-for-hgsetget-derived-class#answer_144336">discovered</a> by Oleg Komarov (<a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/simulink/ug/limit-property-values-to-a-finite-set-of-strings-1.html">additional details</a>; <a target="_blank" href="/articles/class-object-tab-completion-and-improper-field-names">additional aspects of class property tab-completion</a>):</p>
<pre lang='matlab'>
classdef foo < matlab.System
    properties
        Coordinates
    end
    properties(Hidden,Transient)
        CoordinatesSet = matlab.system.StringSet({'north','south','east','west'});
    end
end
</pre>
<p><center><img loading="lazy" decoding="async" alt="restricting Matlab property values" src="https://www.mathworks.com/matlabcentral/answers/uploaded_files/15194/Capture.PNG" title="restricting Matlab property values" width="309" height="129"/></center></p>
<hr />
<p><b><u>Addendum April 8, 2015</u></b>: As reported by Martin A. <a target="_blank" href="/articles/plot-legend-title#comment-347508">here</a> and also <a target="_blank" href="/articles/setting-class-property-types#comment-343150">below</a>, R2015a has apparently added the new (and hidden) <em>Type</em> property to the <em>meta.property</em> class and the <em>InputTypes</em> and <em>OutputTypes</em> properties to the the <em>meta.method</em> class. This enables specifying and querying the types of properties as well as method inputs/outputs. For example:</p>
<pre lang="matlab">
mc = ?matlab.graphics.axis.Axes;
mc.PropertyList(1).Name % Camera
mc.PropertyList(1).Type % matlab.graphics.axis.camera.Camera
mc.MethodList(49).Name % addlistener
mc.MethodList(49).InputNames % [sources, propertyname, eventname, callback]
mc.MethodList(49).InputTypes % [handle, asciiString, char vector, function_handle scalar]
</pre>
<hr />
<p><b><u>Addendum November 11, 2015</u></b>: <a href="/articles/setting-class-property-types#comment-362420">Apparently</a>, when using the <code>@double</code> syntax, Matlab only allows the property to receive real values. In order to enable complex values, we can also add the undocumented "complex" attribute. Note that we have to enter the dimensionality (scalar/vector/matrix) first, since "complex" is not accepted as a valid dimensionality value. For example:</p>
<pre lang='matlab' highlight='4,11'>
% This is ok:
classdef foo
    properties
        bar@double scalar complex = 1 + 2i
    end
end
% This causes an error:
classdef foo
    properties
        bar@double complex = 1 + 2i
    end
end
</pre>
<hr />
<p><b><u>Addendum April 28, 2016</u></b>: Matlab R2016a now has a similar documented functionality. However, I feel that there are important drawbacks to the new functionality compared to the one presented here. Read the <a href="/articles/setting-class-property-types-2" target="_blank">full discussion about this</a>.<br />
The new (documented) syntax automatically type-casts the data to the specified data type, were possible, something that the undocumented (@) syntax presented above does not. In other words, the undocumented syntax is stricter and expects the data to be exactly the specified data type, without attempting any type-casting. As <a href="/articles/setting-class-property-types-2#comment-375230" target="_blank">reported by Martin Afanasjew</a>, we can add the <code>property</code> attribute to the data type to replicate the new syntax's automatic type-casting:</p>
<pre lang="matlab" highlight='4'>
classdef foo
    properties
        prop1@char = 'A'  % will only accept char inputs, not numeric values
        prop2@char property = 65  % will automatically type-cast: 65 will be converted to 'A'
    end
end
</pre>
<hr />
<p><b><u>Addendum September 30, 2022</u></b>: Matlab R2022a has made the legacy @ syntax unsupported, displaying an error message about it in the Matlab Editor, and generating a run-time error if you try to use a class that uses this syntax.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/setting-class-property-types">Setting class property types</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/setting-class-property-types-2" rel="bookmark" title="Setting class property types &#8211; take 2">Setting class property types &#8211; take 2 </a> <small>R2016a saw the addition of class property types. However, a better alternative has existed for many years. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/handle-object-as-default-class-property-value" rel="bookmark" title="Handle object as default class property value">Handle object as default class property value </a> <small>MCOS property initialization has a documented but unexpected behavior that could cause many bugs in user code. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/getting-default-hg-property-values" rel="bookmark" title="Getting default HG property values">Getting default HG property values </a> <small>Matlab has documented how to modify default property values, but not how to get the full list of current defaults. This article explains how to do this. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/types-of-undocumented-matlab-aspects" rel="bookmark" title="Types of undocumented Matlab aspects">Types of undocumented Matlab aspects </a> <small>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/setting-class-property-types/feed</wfw:commentRss>
			<slash:comments>41</slash:comments>
		
		
			</item>
	</channel>
</rss>
