<?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>Search Results for &#8220;UDD&#8221; &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/search/UDD/feed/rss2/" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Sun, 13 Oct 2024 07:18:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>Interesting Matlab puzzle</title>
		<link>https://undocumentedmatlab.com/articles/interesting-matlab-puzzle?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=interesting-matlab-puzzle</link>
					<comments>https://undocumentedmatlab.com/articles/interesting-matlab-puzzle#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sun, 31 Mar 2019 10:15:06 +0000</pubDate>
				<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=8614</guid>

					<description><![CDATA[<p>A simple Matlab puzzle that leads to interesting insight on Matlab's parser. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/interesting-matlab-puzzle">Interesting Matlab puzzle</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/interesting-matlab-puzzle-analysis" rel="bookmark" title="Interesting Matlab puzzle &#8211; analysis">Interesting Matlab puzzle &#8211; analysis </a> <small>Solution and analysis of a simple Matlab puzzle that leads to interesting insight on Matlab's parser. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/interesting-uitree-utility" rel="bookmark" title="An interesting uitree utility">An interesting uitree utility </a> <small>ExploreStruct is a utility that shows how custom uitrees can be integrated in Matlab GUI...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/couple-of-bugs-and-workarounds" rel="bookmark" title="A couple of internal Matlab bugs and workarounds">A couple of internal Matlab bugs and workarounds </a> <small>A couple of undocumented Matlab bugs have simple workarounds. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-dde-support" rel="bookmark" title="Matlab DDE support">Matlab DDE support </a> <small>Windows DDE is an unsupported and undocumented feature of Matlab, that can be used to improve the work-flow in the Windows environment...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Here&#8217;s a nice little puzzle that came to me from long-time Matlab veteran <a href="https://apjanke.net" rel="nofollow" target="_blank">Andrew Janke</a>:<br />
Without actually running the following code in Matlab, what do you expect its output to be? &#8216;Yaba&#8217;? &#8216;Daba&#8217;? perhaps &#8216;Doo!&#8217;? or maybe it won&#8217;t run at all because of a parsing error?</p>
<pre lang="matlab">
function test
    try
        if (false) or (true)
            disp('Yaba');
        else
            disp('Daba');
        end
    catch
        disp('Doo!');
    end
end
</pre>
<p>To muddy the waters a bit, do you think that <a href="https://www.mathworks.com/help/matlab/ref/logicaloperatorsshortcircuit.html" rel="nofollow" target="_blank">short-circuit evaluation</a> is at work here? or perhaps eager evaluation? or perhaps neither?<br />
Would the results be different if we switched the order of the conditional operands, i.e. <code>(true) or (false)</code> instead of <code>(false) or (true)</code>? if so, how and why?<br />
And does it matter if I used &#8220;<code>false</code>&#8221; or &#8220;<code>10&lt; 9.9</code>&#8221; as the &#8220;or&#8221; conditional?<br />
Are the parentheses around the conditions important? would the results be any different without these parentheses?<br />
In other words, how and why would the results change for the following variants?</p>
<pre lang="matlab">
        if (false) or (true)     % variant #1
        if (true)  or (false)    % variant #2
        if (true)  or (10< 9.9)  % variant #3
        if  true   or  10< 9.9   % variant #4
        if 10> 9.9 or  10< 9.9   % variant #5
</pre>
<p>Please post your thoughts in a comment below (expected results and the reason, for the main code snippet above and its variants), and then run the code. You might be surprised at the results, but not less importantly at the reasons. This deceivingly innocuous code snippet leads to interesting insight on Matlab's parser.<br />
Full marks will go to the first person who posts the correct results and reasoning/interpretation of the variants above (hint: it's not as trivial as it might look at first glance).<br />
<b><u>Addendum April 9, 2019</u></b>: I have now posted my solution/analysis of this puzzle <a href="https://undocumentedmatlab.com/articles/interesting-matlab-puzzle-analysis" target="_blank">here</a>.</p>
<h3 id="USA">USA visit</h3>
<p>I will be travelling in the US (Boston, New York, Baltimore) in May/June 2019. Please let me know (altmany at gmail) if you would like to schedule a meeting or onsite visit for consulting/training, or perhaps just to explore the possibility of my professional assistance to your Matlab programming needs.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/interesting-matlab-puzzle">Interesting Matlab puzzle</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/interesting-matlab-puzzle-analysis" rel="bookmark" title="Interesting Matlab puzzle &#8211; analysis">Interesting Matlab puzzle &#8211; analysis </a> <small>Solution and analysis of a simple Matlab puzzle that leads to interesting insight on Matlab's parser. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/interesting-uitree-utility" rel="bookmark" title="An interesting uitree utility">An interesting uitree utility </a> <small>ExploreStruct is a utility that shows how custom uitrees can be integrated in Matlab GUI...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/couple-of-bugs-and-workarounds" rel="bookmark" title="A couple of internal Matlab bugs and workarounds">A couple of internal Matlab bugs and workarounds </a> <small>A couple of undocumented Matlab bugs have simple workarounds. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-dde-support" rel="bookmark" title="Matlab DDE support">Matlab DDE support </a> <small>Windows DDE is an unsupported and undocumented feature of Matlab, that can be used to improve the work-flow in the Windows environment...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/interesting-matlab-puzzle/feed</wfw:commentRss>
			<slash:comments>20</slash:comments>
		
		
			</item>
		<item>
		<title>Reviews and testimonials</title>
		<link>https://undocumentedmatlab.com/ib-matlab/reviews?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=reviews</link>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sun, 17 Mar 2019 08:41:22 +0000</pubDate>
				<guid isPermaLink="false">http://undocumentedmatlab.com/?page_id=8476</guid>

					<description><![CDATA[<p>Professional reviews So, do we like it? Well, IB-MATLAB is robust, very easy to learn how to use and does exactly what it claims to do &#8211; namely provide a simple and efficient order interface between MATLAB and Interactive Brokers&#8217; API. It also costs peanuts&#8230; So yes, we like it &#8211; a lot. &#8211; Andy [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/ib-matlab/reviews">Reviews and testimonials</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/iqml/reviews" rel="bookmark" title="Reviews and testimonials">Reviews and testimonials </a> <small>&#8220;Simply put, IQML just works. Having struggled with Matlab&#8217;s data feed toolbox and many frustrated support calls, I found the IQML product. What a night and day experience! Not only does the product allow you to easily access the entire...</small></li>
<li><a href="https://undocumentedmatlab.com/development/testimonials" rel="bookmark" title="Testimonials">Testimonials </a> <small>&#8220;Yair knows to share his enormous Matlab knowledge in a very efficient and flexible way. The training was structured very well and contained a good and detailed introduction in object oriented Matlab programming. At the same time it contained a...</small></li>
<li><a href="https://undocumentedmatlab.com/ib-matlab/documentation" rel="bookmark" title="IB-Matlab documentation">IB-Matlab documentation </a> <small>Documentation IB-Matlab&#8217;s main product page Quick-reference help Full User Guide (PDF) Usage syntax details &#8211; see below Usage examples Questions &amp; Answers Real-time trading system demo that uses IB-Matlab, presented at the MATLAB Computational Finance Conference in New York in...</small></li>
<li><a href="https://undocumentedmatlab.com/ib-matlab/product-comparison" rel="bookmark" title="Product comparison">Product comparison </a> <small>Access market/portfolio data and submit trade orders in Matlab via Interactive Brokers (IB). IB-Matlab provides an easy-to-use Matlab interface to InteractiveBrokers, enabling quants, algo traders and ordinary folk to easily leverage Matlab's superior analysis and visualization capabilities, with the IB...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<h3 id="reviews">Professional reviews</h3>
<p><span class="alignright"><img decoding="async" title="AutomatedTrader magazine" src="https://undocumentedmatlab.com/images/AT_Logo_Stacked_300x159.gif" alt="AutomatedTrader magazine" width="300" height="159"/></span><i>So, do we like it? Well, IB-MATLAB is robust, very easy to learn how to use and does exactly what it claims to do &#8211; namely provide a simple and efficient order interface between MATLAB and Interactive Brokers&#8217; API. It also costs peanuts&#8230;<br />
So yes, we like it &#8211; a lot.</i></p>
<blockquote><p>&#8211; Andy Webb, Automated Trader magazine, Q3 2011 (<a target="_blank" rel="nofollow" href="http://www.automatedtrader.net/articles/software-review/84091/the-virtue-of-simplicity">&#8220;The Virtue of Simplicity&#8221; article online</a>; or <a target="_blank" href="/files/IB-Matlab_Review.pdf">downloadable PDF</a>)</p></blockquote>
<p><i>All told, we regarded the enhancements to IB-MATLAB since we last reviewed it as significant. The order submission process was rock solid as before, but the new capabilities really open up the possibilities &#8211; especially for trading that is analytically intensive but not high frequency. We were able to deploy multiple models in real time to IB&#8217;s trading platform without any difficulties or glitches. &#8230;<br />
IB-MATLAB effectively contradicts the declaration we&#8217;ve seen on more than a few web sites that “MATLAB is not for real time trading”.</i></p>
<blockquote><p>&#8211; Andy Webb, Automated Trader magazine, Q1 2012 (<a target="_blank" rel="nofollow" href="http://www.automatedtrader.net/articles/software-review/107768/mashup">&#8220;Mashup!&#8221; article online</a>; or <a target="_blank" href="/files/IB-Matlab_Review2.pdf">downloadable PDF</a>)</p></blockquote>
<p style="margin-bottom: 20px;">
<p><figure style="width: 300px" class="wp-caption alignright"><a target="_blank" rel="nofollow" href="https://youtu.be/Mh8IaC-LRGQ?t=146"><img decoding="async" alt="Click to view the Algorithmic Trading System presentation video" src="https://undocumentedmatlab.com/images/IB-Matlab_Chris_Reeves_Video_300x149.png" title="Click to view the Algorithmic Trading System presentation video" width="300" height="149" /></a><figcaption class="wp-caption-text">Click to view the presentation video</figcaption></figure> <i>Easy integration with IB through IB-Matlab&#8230; The Trading Toolbox isn&#8217;t very robust, it&#8217;s really buggy, &#8230; I would love to get the Trading Toolbox up and running, but I think that Yair has got it covered for Interactive Brokers, I just use his program&#8230;<br />
IB-Matlab is our wrapper for the IB API, so that we don&#8217;t have to write our own Java connector. IB-Matlab is a robust Java connector, complete wrapper for the IB API. A cheap investment, it&#8217;s definitely worth it. I can&#8217;t even stress enough how much time it will save you. Don&#8217;t build from scratch, it is cheaper and faster to buy from 3rd-party vendors. If I was to build IB-Matlab it would take me several weeks and for only $400 I could have a turnkey solution, I mean it&#8217;s a no-brainer there&#8230; It&#8217;s better than those retail trading platforms. This is the cheapest professional-grade system that you can get. IB connected to IB-Matlab connected to Matlab connected to the Data-Feed Toolbox connected to IQFeed is the cheapest technology stack that will give you trading robustness.<br />
Yair is extremely helpful, provides great customer support.</i></p>
<blockquote><p>&#8211; Chris Reeves, A2X Capital, Feb 27, 2015 (<a href="https://youtu.be/Mh8IaC-LRGQ?t=146" target="_blank" rel="nofollow">&#8220;Algorithmic Trading System&#8221; video</a>)</p></blockquote>
<p>Also quoted: <i>IB-Matlab is the most robust wrapper for the IB API I have come across. Amazing value for the price!</i></p>
<blockquote><p>&#8211; creeves, Feb 23, 2015 (comment posted about IB-Matlab on <a target="_blank" rel="nofollow" href="https://gdcdyn.interactivebrokers.com/Universal/servlet/MarketPlace.MarketPlaceServlet?action=softwareTools&#038;selectedClient=tradersInvestors">IB&#8217;s Marketplace</a>)</p></blockquote>
<p><i>&#8230;At that point I turned to Yair Altman&#8217;s IB-Matlab product. Happily, this uses IB&#8217;s Java api, which is a great deal more robust than the ActiveX platform. It&#8217;s been some time since I last used IB-Matlab and was pleased to see that Yair has been very busy over the intervening period, building the capabilities of the system and providing very comprehensive documentation for it. With Yair&#8217;s help, it took me no time at all to get up and running and within a day or two the system was executing orders flawlessly in IB&#8217;s TWS. &#8230;<br />
Yair is very generous with his time in providing support to his users and his responses to my questions were fast and detailed.</i></p>
<blockquote><p>&#8211; Jonathan Kinlay, Quantitative Research and Trading, March 5, 2015 (<a href="http://jonathankinlay.com/index.php/2015/03/algorithmic-trading/" target="_blank" rel="nofollow">&#8220;Algorithmic trading&#8221; article</a>)</p></blockquote>
<h3 id="testimonials">User testimonials</h3>
<div class="width_mob_100 alignright" style="width: 510px">
<div class="wp-caption"><a target="_blank" rel="nofollow" href="https://gdcdyn.interactivebrokers.com/Marketplace/InvestorsMarketplace" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','https://gdcdyn.interactivebrokers.com/Marketplace/InvestorsMarketplace']);"><img decoding="async" alt="Click to view the IB Marketplace" src="https://undocumentedmatlab.com/images/Marketplace.png" title="Click to view the IB Marketplace" width="500"></a></p>
<p class="wp-caption-text">Click to view the IB Marketplace</p>
</div>
<div class="div_reviews">
<a href="https://gdcdyn.interactivebrokers.com/Marketplace/InvestorsMarketplace" target="_blank" rel="nofollow"></p>
<div class="reviews" style="width:337px; padding:30px 0 100px 180px; font-family:arial,helvetica,sans-serif!important; font-size:13px; line-height:0;">
<style type="text/css" media="screen">
.ratingRow{white-space:no-wrap; line-height:16px;}
.ratingHead{color:#999999; padding-right:10px; float:left;}
.ratingBg{background-color:#f4f4cf; width:70px; overflow:hidden; float:left; margin-right:1px;}
.ratingFg{background-color:#ffcc66; width:0px; height:14px; border:0;}
.ratingVal{color:#999999;  padding-left:10px; float:left; text-decoration:none;}
</style>
<div style="text-align:center; padding-bottom:2px;"><b>117 reviews</b></div>
<div>
<div class="ratingRow">
<div title="100% of voters rated IB-Matlab with 5 stars!">
<div class="ratingHead" style="color:#000;">5 star</div>
<div class="ratingBg">
<div class="ratingFg" style="width:100%"></div>
</div>
<div class="ratingVal" style="color:#000;">100%</div>
</div>
<p></p>
<div title="0% of voters rated IB-Matlab with 4 stars!">
<div class="ratingHead">4 star</div>
<div class="ratingBg">
<div class="ratingFg"></div>
</div>
<div class="ratingVal">0%</div>
</div>
<p></p>
<div title="0% of voters rated IB-Matlab with 3 stars!">
<div class="ratingHead">3 star</div>
<div class="ratingBg">
<div class="ratingFg"></div>
</div>
<div class="ratingVal">0%</div>
</div>
<p></p>
<div title="0% of voters rated IB-Matlab with 2 stars!">
<div class="ratingHead">2 star</div>
<div class="ratingBg">
<div class="ratingFg"></div>
</div>
<div class="ratingVal">0%</div>
</div>
<p></p>
<div title="0% of voters rated IB-Matlab with 1 star!">
<div class="ratingHead">1 star</div>
<div class="ratingBg">
<div class="ratingFg"></div>
</div>
<div class="ratingVal">0%</div>
</div>
</div>
</div>
</div>
<p></a>
</div>
<p style="text-align: center; "><a target="_blank" href="/ib-matlab/trial-request"><img decoding="async" title="IB-Matlab free trial" src="https://undocumentedmatlab.com/images/download_trial_animated.gif" alt="IB-Matlab free trial" width="290" height="70"></a></p>
</div>
<p>The following testimonials appear on <a target="_blank" rel="nofollow" href="https://gdcdyn.interactivebrokers.com/Marketplace/InvestorsMarketplace">IB&#8217;s Marketplace</a>, where IB-Matlab is the top-rated product, with a perfect rating of 5.000 stars from over 100 independent traders:</p>
<p><i></p>
<ul>
<li>&#8220;Great product! 1) well-written documentation + intuitive to use = I learned how to use it quickly 2) broad range of features = all my trading needs are met 3) whenever I&#8217;ve needed to contact him, the developer, Yair Altman, has been helpful, friendly, and rapidly responsive.&#8221; &#8211; victorqz</li>
<li>&#8220;Solid product, good support, works flawlessly for submitting and managing orders.&#8221; &#8211; emperor</li>
<li>&#8220;Robust, thorough and convenient. Great product!&#8221; &#8211; magpie88</li>
<li>&#8220;The software installs and works seamlessly. The vendor has always been prompt in responding to requests for support and information. I&#8217;ve used this service for approximately 10 years now without any glitches or issues. Solid product!&#8221; &#8211; amoser</li>
<li>&#8220;Very solid software and useful to interface to IB. Save me a lot of effort in my work.&#8221; &#8211; bwws88</li>
<li>&#8220;Fantastic product, works exactly as described. Easy and intuitive to use. Thank you!!!&#8221; &#8211; AndreyP</li>
<li>&#8220;IBMatlab works very well for me. I am impressed by the stability and exception handling. Highly recommended.&#8221; &#8211; debelge</li>
<li>&#8220;Very robust and thorough. Prompt help with issues!&#8221; &#8211; Marton</li>
<li>&#8220;Excellent software, great documentation, and fantastic customer service! I was fully active much faster than planned, saving months of low-level API programming.&#8221; &#8211; mfarsh20</li>
<li>&#8220;When you buy this product, you are dealing directly with the expert programmer who has created and maintains it. Consequently, you get a no-nonsense, accurate-to-the-tee answers to your questions. Implementation has been very well thought out with excellent documentation to get you up and running. A 5-star product&#8230;&#8221; &#8211; InverseI</li>
<li>&#8220;I am retired mechanical engineer and financial advisor. I have been around software services for years and I find Yair and his program IB-Matlab to be very very good. His customer services &#8211; I would say is in the top 3 that I have used across multiple decades. We were able to be &#8220;up and running&#8221; with paper trades extremely fast. Nice to work with a professional. Leo&#8221; &#8211; Engineer</li>
<li>&#8220;100% Amazing! Saved me countless hours. The IB-Matlab package is absolutely the best! Also very well documented. Great work!&#8221; &#8211; MikeMike</li>
<li>&#8220;Fantastic product that works flawlessly and has saved me a lot of work, time and money on developing my trading systems! well done Yair!&#8221; &#8211; mdyson</li>
<li>&#8220;Easy to use with comprehensive manual and good support! It is really help.&#8221; &#8211; rode79</li>
<li>&#8220;I have been using IBMatlab for some years now and it works flawlessly. Very well documented and excellent technical support. Highly recommended.&#8221; &#8211; 6315</li>
<li>&#8220;Best IB-matlab api of ever!!&#8221; &#8211; mcbison</li>
<li>&#8220;IB-Matlab provides absolutely impressive functionality, seamlessly connecting the IB’s trading platform with Matlab and letting you focus on trading.&#8221; &#8211; Aztec</li>
<li>&#8220;Works flawlessly, well documented. The IB integration from Matlab&#8217;s built in Trading Toolbox is terrible, this plugin will have you up and running within minutes&#8221; &#8211; KagenA</li>
<li>&#8220;I have been using this API for few years now, and I find it quite reliable&#8221; – brunovig</li>
<li>&#8220;Robust, reliable and easy to use. Everything I need.&#8221; &#8211; BMA2018</li>
<li>&#8220;Yair has been incredibly helpful and thorough, and his codes run without issue. Worth every penny.&#8221; &#8211; buddingq</li>
<li>&#8220;The trading toolbox from Mathworks is a waste of $. Get IB-Matlab instead. Robust, easy to use, that will pay for itself in rapid development.&#8221; &#8211; MXR64</li>
<li>&#8220;A fantastic product and a unique and fast service! Yair is really very good!!!&#8221; &#8211; ctlsm</li>
<li>&#8220;Exceptional! Product: robust/stable. Provider: responsive with a less than 24 hr turnaround. This system allows any groups to leverage algo trading.&#8221; &#8211; RSRSE</li>
<li>&#8220;Easy to use, excellent support, saves hours in every project. I highly recommend.&#8221; &#8211; RonenY</li>
<li>&#8220;Good quality code. Most API functions work interactively with the option to access all API features. Prompt responses from Yair.&#8221; &#8211; asobolev</li>
<li>&#8220;Very reliable link to IB from Matlab, facilities increase every year.&#8221; &#8211; Kenneth</li>
<li>&#8220;Yair Altman is the author of two treatise-length books on Matlab. This is evident as IB-Matlab corrects many shortcomings of Matlab&#8217;s own interface.&#8221; &#8211; PhiStrat</li>
<li>&#8220;Rock solid product plus fantastic customer service. Yair responds to questions very fast!&#8221; &#8211; Lab715</li>
<li>&#8220;IBMatlab really simplified the creation of a functional trading system in Matlab, and Yair has been helpful and very responsive on all my questions.&#8221; &#8211; brianr</li>
<li>&#8220;Great product that is very stable. The docs are excellent with many examples. Support is top notch as Yair responds quickly to questions.&#8221; &#8211; cbmitch</li>
<li>&#8220;Truly solid product. Easy to work with and has all the functionality to smoothly execute our trading, we have not had a single issue with it.&#8221; &#8211; STCMF</li>
<li>&#8220;This is an excellent product that gives extremely deep access to all the capabilities of IB. Surprisingly easy to use as well!&#8221; &#8211; jones13</li>
<li>&#8220;Super useful and stable. Yair is very responsive!&#8221; &#8211; travlake</li>
<li>&#8220;very usable, easily programmable (for the most part). Robust.&#8221; &#8211; fluffpin</li>
<li>&#8220;An excellent product with a detailed user guide. Quick and detailed support by its developer, Yair, an expert Matlab practitioner. Highly recommended.&#8221; &#8211; T_R</li>
<li>&#8220;Rarely are the claims of a developer so understated. The software is simply a &#8220;must have&#8221; for IB development within Matlab. Thanks to Yair.&#8221; &#8211; kvargas</li>
<li>&#8220;You should charge more for it. Best value for your money. No bugs. Detailed user-guide contains concise explanations. Easy to use and amazing support.&#8221; &#8211; Constant</li>
<li>&#8220;This software is a MUST. 15 days trial, EXCELLENT documentation, top notch support, the API is world class design, CHEAP! easy and yet powerful.&#8221; &#8211; bayes</li>
<li>&#8220;Very quick response. Support is unparalleled professional quality. Software works great, definitely an easy-to-use tool for making money.&#8221; &#8211; CLVoting</li>
<li>&#8220;Yair&#8217;s API is the best and Yair&#8217;s help, support and response time is enviable for any service provider.&#8221; &#8211; m1chael2</li>
<li>&#8220;High quality software with prompt and stable support with user guide details the relevant information for API operations&#8221; &#8211; ccjasia</li>
<li>&#8220;Highly competent, professional, quick turnaround, in-depth understanding of electronic market micro-structure&#8221; &#8211; sgoyvote</li>
<li>&#8220;The software works flawlessly and the support from Yair is unparalleled. Without a doubt worth purchasing.&#8221; &#8211; asselall</li>
<li>&#8220;Super. Wasted too much time trying other solutions eg. trading toolbox. IB-Matlab is the way to go. Robust, logical and very well documented.&#8221; &#8211; jt1010</li>
<li>&#8220;Excellent connector for MatLab. We evaluated it against the Mathworks product and found Yair&#8217;s version far better. We use it on a daily basis.&#8221; &#8211; AP1234</li>
<li>&#8220;Great software &#8211; very helpful to implement own strategies. Comprehensive and easy to use interface to the API. Yair is very responsive and helpful!&#8221; &#8211; quantD</li>
<li>&#8220;Saved me a lot of time realizing some extra tools and automation for my trading. Very robust and easy to use! Can only recommend!&#8221; &#8211; MartinMM</li>
<li>&#8220;Excellent software, easy to use and follow documentation, highly recommend. Yair is extremely responsive and eager to solve all the things you need.&#8221; &#8211; cheers</li>
<li>&#8220;Code works and is easy to install and interface with in Matlab. Code is well documented as well.&#8221; &#8211; ericdonn</li>
<li>&#8220;Highly recommended product. Easy to use, robust, inexpensive, quick and quality support from the developer. High value product for the money.&#8221; &#8211; scap</li>
<li>&#8220;Amazing interface! Prompt replies to emails. Robust connector, no issues faced yet. Will certainly recommend to anyone looking to use MATLAB with IB.&#8221; &#8211; harjas</li>
<li>&#8220;Highly recommend for anyone doing automated trading. The IB interface routines are very easy to learn and integrate. Powerful combination with Matlab.&#8221; &#8211; ber7t</li>
<li>&#8220;Very good product. Easy to follow documentation. Yair is very quick on email. Highly recommended to anyone looking for an IB to Matlab connection.&#8221; &#8211; even</li>
<li>&#8220;IB-Matlab is excellent. The connection is robust, the documentation is comprehensive and well written, and Yair is very helpful.&#8221; &#8211; Markmaj</li>
<li>&#8220;We hired Yair to write some functions for our prop-shop. Got excellent help within 10 hours and he is eager to solve all the things you need.&#8221; &#8211; johlof</li>
<li>&#8220;Clean application that nicely bridges the gap between Matlab and IB. Helpful service when you need it. Everything works as expected.&#8221; &#8211; johnd</li>
<li>&#8220;Easy to use. Very comprehensive user guide. Great support from the founder&#8221; &#8211; EAfb</li>
<li>&#8220;Robust!! Quick turnaround service!&#8221; &#8211; Anon</li>
<li>&#8220;IBMatlab has allowed me to accelerate project development by many months and comes with great product support.&#8221; &#8211; james_r</li>
<li>&#8220;Everyone should buy it. Price is reasonable. I have been using it for three years.&#8221; &#8211; flash201</li>
<li>&#8220;System has worked flawlessly for the past year. Yair is extremely responsive (I&#8217;m not sure when he sleeps) and helpful. Excellent value.&#8221; &#8211; billj</li>
<li>&#8220;IB-Matlab is the most robust wrapper for the IB API I have come across. Amazing value for the price!!&#8221; &#8211; creeves</li>
<li>&#8220;IBMatlab has been invaluable to test trading strategies; it is reliable and includes lots of useful functions. Yair is very responsive and helpful.&#8221; &#8211; algo1410</li>
<li>&#8220;Excellent software &#8211; I&#8217;ve been looking for something like this for almost a year now. 5/5&#8221; &#8211; sysdo</li>
<li>&#8220;Yair has made a great product and offers valuable support. Good for risk management and data analysis tools and recommend it.&#8221; &#8211; mkrause</li>
<li>&#8220;IB-Matlab is an excellent product. It is very solid and Yair is very quick in responding to inquiries. Strongly recommend it !&#8221; &#8211; FinLab</li>
<li>&#8220;Support is prompt. Easy to use. Speed is not as quick as I thought. Anyway, it might be due to delay from IB.&#8221; – JeffKoh</li>
<li>&#8220;IB-Matlab provides an excellent range of tools for automated trading systems. Support excellent and prompt. 100% stable in live operation.&#8221; &#8211; sunbear6</li>
<li>&#8220;I&#8217;ve been using it for over a year and I have no complaints. It is robust and does what it is supposed to do. Very quick customer service.&#8221; &#8211; hank99</li>
<li>&#8220;Very helpful interactive link to TWS. Saves hundreds of man-hours in developing custom features.&#8221; &#8211; cekaulII</li>
<li>&#8220;I find it quite reliable and easy to use. I was able to code a real time automatic trading system relatively easily. The service behind is excellent.&#8221; &#8211; khalfina</li>
<li>&#8220;I have been using IB-Matlab for almost 3 years and have found it to work perfectly. Yair responds promptly to questions with detailed answers.&#8221; &#8211; kChuck</li>
<li>&#8220;Amazing product. Running it for last one month. Stable. No instance of breakdown. Mr. Altman is very quick in response time. Highly recommended.&#8221; &#8211; sujitm</li>
<li>&#8220;IBMatlab is a very convenient way to access IB&#8217;s API. The documentation is comprehensive and it is easy to integrate the software into MATLAB code.&#8221; &#8211; prateek1</li>
<li>&#8220;Excellent product, top-notch tech support.&#8221; &#8211; nobull</li>
<li>&#8220;Excellent knowledge on Matlab, Java and IB &#8211; perfect for automated trading. It was a real joy and I will work with them again.&#8221; &#8211; human123</li>
<li>&#8220;Excellent software product, customer support and seamless integration. Totally reliable and a superb addition for automated trading.&#8221; &#8211; gazza75</li>
<li>&#8220;This product is reliable and well documented. The creator is always quick to respond and helpful.&#8221; &#8211; MacKG</li>
<li>&#8220;I have been using IB-Matlab for three months now and it has been flawless. Great value.&#8221; &#8211; wajv</li>
<li>&#8220;IB-Matlab is an easy to use end-to-end solution for Matlab users.&#8221; &#8211; BenTam</li>
<li>&#8220;Excellent. Saves $1600 from Mathworks&#8217; built-in solution.&#8221; &#8211; muller</li>
<li>&#8220;A quality product at a good price. I find it to work better and in a more flexible way than Matlab&#8217;s own IB toolbox.&#8221; &#8211; Vasastan</li>
<li>&#8220;IB-Matlab allows me to perform fully automated trading, using my own developed code. Yair&#8217;s support is very professional. I highly recommend it.&#8221; &#8211; wimvwijn</li>
<li>&#8220;IB-Matlab is a tremendous product. The documentation is outstanding and Yair is INCREDIBLY responsive to any questions or issues which arise.&#8221; &#8211; wgpCap</li>
<li>&#8220;I found Yair Altman readily reachable when I have questions and the product has performed well.&#8221; &#8211; hwshiau</li>
<li>&#8220;IB-Matlab lets you harness the depth and efficiency of MATLAB! It&#8217;s intuitive, robust, full-featured, and affordable. Great documentation and support.&#8221; &#8211; JTrade</li>
<li>&#8220;IBMatlab is a professional Matlab TWS API interface. It works very reliable and is easy to use. The support is very client focused and supportive.&#8221; &#8211; drepl</li>
<li>&#8220;Excellent product, responsive support and very useful examples/documentation to get you up and running without much work. Highly recommend!&#8221; &#8211; CharlesM</li>
<li>&#8220;Robust product, user-friendly, hard to say no with the price and level of support. Highly recommended.&#8221; &#8211; stephenw</li>
<li>&#8220;Great product! Stable platform, very flexible, great support, and easily scaled to implement any automated trading strategy. Well worth the money!&#8221; &#8211; BenM</li>
<li>&#8220;Worth every dime and excellent support. The possibilities with the combination Matlab/IB seem limitless. The resulting mac system is extremely stable.&#8221; &#8211; onmac</li>
<li>&#8220;Great product that allows one to utilize the power and flexibility of Matlab to create automated systems.&#8221; &#8211; jbusse00</li>
<li>&#8220;Good product (IBMatlab): Good range of functionality, Good performance, Good documentation and very good support from Yair.&#8221; &#8211; unbroken</li>
<li>&#8220;As a former control system engineer, I used MATLAB. I was very excited to hear about IBMatlab. IBMatlab works! Highly recommend!&#8221; &#8211; kiscl</li>
</ul>
<p></i></p>
<p><span class="alignright" style="width: 130px; height: 32px; background: url(//undocumentedmatlab.com/images/star_26x26.gif) 0 0 repeat-x; margin: 0 50px 0 20px;"></span>These quotes are from real IB traders, who took the time to comment anonymously about IB-Matlab on IB&#8217;s website using IB&#8217;s system. Over 100 traders have anonymously rated IB-Matlab on IB&#8217;s website – all of them, without exception, rated IB-Matlab with a perfect 5-star rating. Such perfect rating and superlatives from so many independent traders is unparalleled by any other program on the IB Marketplace. Numerous other traders have provided similar statements about IB-Matlab by private email. </p>
<p>We take great pride in providing a great product, fantastic value, and excellent customer service.</p>
<h3 id="Trial">Free trial version</h3>
<p>A fully-functional free trial version is available &#8211; just <!-- a href="mailto:%20altmany%20@gmail.com?subject=IB-Matlab%20trial&amp;body=Hi%20Yair,%20&amp;cc=;&amp;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=IB-Matlab%20trial&amp;body=Hello, I would like to request the free fully-functional trial of IB-Matlab. '); return false;" --><a target="_blank" href="/ib-matlab/trial-request">request your trial</a> and you will get a no-obligations copy with detailed installation and usage instructions.</p>
<p>There are absolutely no strings attached: the trial is completely free and fully functional, just limited in duration.</p>
<p>You only need the basic Matlab, no toolbox is required. You can be up and running within minutes. We are confident that you will love the product, so we encourage you to test it:<br />
<span class="alignright"><img loading="lazy" decoding="async" title="IB-Matlab connectivity (Matlab and TWS may be on separate computers)" src="https://undocumentedmatlab.com/images/IB-Matlab.png" alt="IB-Matlab connectivity (Matlab and TWS may be on separate computers)" width="426" height="213"/></span></p>
<style type="text/css" media="screen">
.entry-content label {
color: #888;
font-size: 12px;
display: inline-block;
width: 190px;
vertical-align: top;
}
.entry-content input, select {margin-bottom: 12px;}
.entry-content textarea {margin-bottom: 0px;}
</style>
<div class="form_matlab" style="margin-bottom: 12px;">
<form id="form-3-1754640467" method="post" action="/search/UDD/feed/rss2/" class=" customcontactform">

<div>
<label for="name">* Your full name</label>
<input class=" "  id="name-1754640467" type="text" name="name" value="" />
</div>
<div>
<label for="business_name">Organization name (optional)</label>
<input class=" ccf-tooltip-field" title="Enter the name of your organization (optional)"  id="business_name-1754640467" type="text" name="business_name" value="" />
</div>
<div>
<label for="fixedEmail">* Your email</label>
<input class=" ccf-tooltip-field" title="Please enter your email address. (required)"  id="fixedEmail-1754640467" type="text" name="fixedEmail" value="" maxlength="100" />
</div>
<div>
<label for="have_IB">* I have an active IB account</label>
<select title="You need to have an active IB account to use IB-Matlab. (required)"  id="have_IB-1754640467" name="have_IB" class=" ccf-tooltip-field">
<option value="ccf-dead-state">Please select</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
</div>
<div>
<label for="have_Matlab">* I have Matlab R2008a or newer</label>
<select title="IB-Matlab works best with R2008a or newer. If you have an older Matlab version, contact us by email for a custom product. (required)"  id="have_Matlab-1754640467" name="have_Matlab" class=" ccf-tooltip-field">
<option value="ccf-dead-state">Please select</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
</div>
<div>
<img loading="lazy" decoding="async" width="96" height="24" alt="Captcha image for Custom Contact Forms plugin. You must type the numbers shown in the image" id="captcha-image" src="https://undocumentedmatlab.com/wp-content/plugins/custom-contact-forms/image.php?fid=3" /> 
			<div><label for="captcha3">* Type the numbers</label> <input class=" ccf-tooltip-field" type="text" title="Type the numbers displayed in the image above." name="captcha" id="captcha3" maxlength="20" /></div>
</div>
<input name="form_page" value="/search/UDD/feed/rss2/" type="hidden" />
<input type="hidden" name="fid" value="3" />

<input type="submit" id="submit-3-1754640467" class="submit" value="Submit" name="customcontactforms_submit" />
</form>
</div>
<p>You will receive the trial installation instructions to your specified email within 24 hours. If you do not get an email within 24 hours, then please check your email&#8217;s spam folder, or send a direct email to altmany at gmail.com</p>
<p><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/email-icon.png" width="32" height="22" alt="" style="vertical-align:middle;border:0"/>&nbsp;<a href="mailto: altmany @gmail.com?subject=IB-Matlab&#038;body=Hi Yair, &#038;cc=;&#038;bcc=" rel="nofollow" target="_blank" onclick="var n='altmany'; var d='gmail.com'; window.open('mailto:'+n+'@'+d+'?subject=IB-Matlab&#038;body=Hi Yair, '); return false;">Contact us</a></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/ib-matlab/reviews">Reviews and testimonials</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/iqml/reviews" rel="bookmark" title="Reviews and testimonials">Reviews and testimonials </a> <small>&#8220;Simply put, IQML just works. Having struggled with Matlab&#8217;s data feed toolbox and many frustrated support calls, I found the IQML product. What a night and day experience! Not only does the product allow you to easily access the entire...</small></li>
<li><a href="https://undocumentedmatlab.com/development/testimonials" rel="bookmark" title="Testimonials">Testimonials </a> <small>&#8220;Yair knows to share his enormous Matlab knowledge in a very efficient and flexible way. The training was structured very well and contained a good and detailed introduction in object oriented Matlab programming. At the same time it contained a...</small></li>
<li><a href="https://undocumentedmatlab.com/ib-matlab/documentation" rel="bookmark" title="IB-Matlab documentation">IB-Matlab documentation </a> <small>Documentation IB-Matlab&#8217;s main product page Quick-reference help Full User Guide (PDF) Usage syntax details &#8211; see below Usage examples Questions &amp; Answers Real-time trading system demo that uses IB-Matlab, presented at the MATLAB Computational Finance Conference in New York in...</small></li>
<li><a href="https://undocumentedmatlab.com/ib-matlab/product-comparison" rel="bookmark" title="Product comparison">Product comparison </a> <small>Access market/portfolio data and submit trade orders in Matlab via Interactive Brokers (IB). IB-Matlab provides an easy-to-use Matlab interface to InteractiveBrokers, enabling quants, algo traders and ordinary folk to easily leverage Matlab's superior analysis and visualization capabilities, with the IB...</small></li>
</ol>
</div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Matlab compilation quirks &#8211; take 2</title>
		<link>https://undocumentedmatlab.com/articles/matlab-compilation-quirks-take-2?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlab-compilation-quirks-take-2</link>
					<comments>https://undocumentedmatlab.com/articles/matlab-compilation-quirks-take-2#respond</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 31 May 2017 18:00:42 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Toolbox]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Compiler]]></category>
		<category><![CDATA[Hanan Kavitz]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6919</guid>

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

					<description><![CDATA[<p>It is easy and very useful to attach dynamic properties to Matlab graphics objects in run-time. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles">Adding dynamic properties to graphic handles</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/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/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/graphic-sizing-in-matlab-r2015b" rel="bookmark" title="Graphic sizing in Matlab R2015b">Graphic sizing in Matlab R2015b </a> <small>Matlab release R2015b's new "DPI-aware" nature broke some important functionality. Here's what can be done... ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-properties" rel="bookmark" title="UDD Properties">UDD Properties </a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A client recently asked me to extend one of Matlab&#8217;s built-in graphic containers (<a target="_blank" href="/articles/matlab-layout-managers-uicontainer-and-relatives"><i><b>uiflowcontainer</b></i></a> in this specific case) with automatic scrollbars that would enable the container to act as a scroll-panel. The basic idea would be to dynamically monitor the container&#8217;s contents and when it is determined that they overflow the container&#8217;s boundaries, then attach horizontal/vertical scrollbars to enable scrolling the contents into view:<br />
<center><figure style="width: 350px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Scrollable Matlab container" src="https://undocumentedmatlab.com/images/uiflowcontainer_scroll.gif" title="Scrollable Matlab container" width="350" height="260" /><figcaption class="wp-caption-text">Scrollable Matlab container</figcaption></figure></center><br />
This may sound simple, but there are actually quite a few undocumented hacks that make this possible, including listening to <code>ObjectChildAdded/ObjectChildRemoved</code> events, location/size/visibility events, layout changes etc. Maybe I&#8217;ll blog about it in some future article.<br />
Today&#8217;s post is focused on a specific aspect of this project, attaching dynamic properties to the builtin <i><b>uiflowcontainer</b></i>, that would enable users to modify the container&#8217;s properties directly, as well as control aspects of the scrolling using the new properties: handles to the parent container, as well as the horizontal and vertical scrollbars, and even a new <i>refresh()</i> method.<br />
<span id="more-6006"></span><br />
The &#8220;textbook&#8221; approach to this would naturally be to create a new class that extends (inherits) <i><b>uiflowcontainer</b></i> and includes these new properties and methods. Unfortunately, for some reason that escapes my understanding, MathWorks saw fit to make all of its end-use graphic object classes <code>Sealed</code>, such that they cannot be extended by users. I did ask for this to be changed long ago, but the powers that be apparently decided that it&#8217;s better this way.<br />
So the fallback would be to create our own dedicated class having all the new properties as well as those of the original container, and ensure that all the property values are synchronized in both directions. This is probably achievable, if you have a spare few days and a masochistic state of mind. Being the lazy bum and authority-rebel that I am, I decided to take an alternate approach that would simply add my new properties to the built-in container handle. The secret lies in the undocumented function <i><b>schema.prop</b></i> (for HG1, R2014a and older) and the fully-documented <i><b>addprop</b></i> function (for HG2, R2014b and newer).<br />
In the examples below I use a panel, but this mechanism works equally well on any Matlab HG object: axes, lines, uicontrols, figures, etc.</p>
<h3 id="HG2">HG2 &#8211; addprop function</h3>
<p>The <i><b>addprop</b></i> function is actually a public method of the <code>dynamicprops</code> class. Both the <code>dynamicprops</code> class as well as its <i><b>addprop</b></i> function are <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/dynamicprops.addprop.html">fully documented</a>. What is NOT documented, as far as I could tell, is that all of Matlab&#8217;s builtin handle graphics objects indirectly inherit <code>dynamicprops</code>, via <code>matlab.graphics.Graphics</code>, which is a high-level superclass for all HG objects. The bottom line is that we can dynamically add run-time properties to any HG object, without affecting any other object. In other words, the new properties will only be added to the handles that we specifically request, and not to any others. This suits me just fine:</p>
<pre lang='matlab'>
hProp = addprop(hPanel, 'hHorizontalScrollBar');
hPanel.hHorizontalScrollBar = hMyScrollbar;
hProp.SetAccess = 'private';  % make this property read-only
</pre>
<p>The new property <code>hHorizontalScrollBar</code> is now added to the <code>hPanel</code> handle, and can be accessed just like any other read-only property. For example:</p>
<div class="wp_syntax">
<div class="code">
<pre class="matlab" style="font-family:monospace;">&gt;&gt; <span style="color: #0000FF;">get</span><span style="color: #080;">(</span>hPanel, <span style="color:#A020F0;">'hHorizontalScrollBar'</span><span style="color: #080;">)</span>
<span style="color: #0000FF;">ans</span> =
    JavaWrapper
&gt;&gt; hPanel.<span style="">hHorizontalScrollBar</span>
<span style="color: #0000FF;">ans</span> =
    JavaWrapper
&gt;&gt; hPanel.<span style="">hHorizontalScrollBar</span> = <span style="color: #33f;">123</span>
<span style="color: #FF0000;">You cannot set the read-only property 'hHorizontalScrollBar' of UIFlowContainer.</span></pre>
</div>
</div>
<p>Adding new methods is more tricky, since we do not have a corresponding <i>addmethod</i> function. The trick I used was to create a new property having the requested new method&#8217;s name, and set its read-only value to a handle of the requested function. For example:</p>
<pre lang='matlab'>
hProp = addprop(hPanel, 'refresh');
hPanel.refresh = @myRefreshFunc;
hProp.SetAccess = 'private';  % make this property read-only
</pre>
<p>We can then invoke the new <i>refresh</i> &#8220;method&#8221; using the familiar dot-notation:</p>
<pre lang='matlab'>hPanel.refresh();</pre>
<p>Note: if you ever need to modify the initial value in your code, you should revert the property&#8217;s <b>SetAccess</b> meta-property to <code>'public'</code> before Matlab will enable you to modify the value:</p>
<pre lang='matlab'>
try
    % This will raise an exception if the property already exists
    hProp = addprop(hPanel, propName);
catch
    % Property already exists - find it and set its access to public
    hProp = findprop(hPanel, propName);
    hProp.SetAccess = 'public';
end
hPanel.(propName) = newValue;
</pre>
<h3 id="HG1">HG1 &#8211; schema.prop function</h3>
<p>In HG1 (R2014a and earlier), we can use the undocumented <i><b>schema.prop</b></i> function to add a new property to any HG handle (which is a numeric value in HG1). Donn Shull <a target="_blank" href="/articles/udd-properties">wrote about <i><b>schema.prop</b></i></a> back in 2011, as part of his series of articles on UDD (Unified Data Dictionary, MCOS&#8217;s precursor). In fact, <i><b>schema.prop</b></i> is so useful that it has its own <a target="_blank" href="/articles/tag/schemaprop">blog tag here</a> and appears in no less than 15 separate articles (excluding today). With HG2&#8217;s debut 2 years ago, MathWorks tried very hard to rid the Matlab code corpus of all the legacy schema-based, replacing most major functionalities with MCOS-based HG2 code. But so far it has proven impossible to get rid of schema completely, and so schema code is still used extensively in Matlab to this day (R2015b). Search your Matlab path for &#8220;schema.prop&#8221; and see for yourself.<br />
Anyway, the basic syntax is this:</p>
<pre lang='matlab'>hProp = schema.prop(hPanel, propName, 'mxArray');</pre>
<p>The <code>'mxArray'</code> specifies that the new property can accept any data type. We can limit the property to only accept certain types of data by specifying a less-generic data type, among those recognized by UDD (<a target="_blank" href="/articles/udd-properties#DataType">details</a>).<br />
Note that the meta-properties of the returned <code>hProp</code> are somewhat different from those of HG2&#8217;s <code>hProp</code>. Taking this into account, here is a unified function that adds/updates a new property (with optional initial value) to any HG1/HG2 object:</p>
<pre lang='matlab'>
function addProp(hObject, propName, initialValue, isReadOnly)
    try
        hProp = addprop(hObject, propName);  % HG2
    catch
        try
            hProp = schema.prop(hObject, propName, 'mxArray');  % HG1
        catch
            hProp = findprop(hObject, propName);
        end
    end
    if nargin > 2
        try
            hProp.SetAccess = 'public';  % HG2
        catch
            hProp.AccessFlags.PublicSet = 'on';  % HG1
        end
        hObject.(propName) = initialValue;
    end
    if nargin > 3 && isReadOnly
        try
            % Set the property as read-only
            hProp.SetAccess = 'private';  % HG2
        catch
            hProp.AccessFlags.PublicSet = 'off';  % HG1
        end
    end
end
</pre>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles">Adding dynamic properties to graphic handles</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/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/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/graphic-sizing-in-matlab-r2015b" rel="bookmark" title="Graphic sizing in Matlab R2015b">Graphic sizing in Matlab R2015b </a> <small>Matlab release R2015b's new "DPI-aware" nature broke some important functionality. Here's what can be done... ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/udd-properties" rel="bookmark" title="UDD Properties">UDD Properties </a> <small>UDD provides a very convenient way to add customizable properties to existing Matlab object handles...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/adding-dynamic-properties-to-graphic-handles/feed</wfw:commentRss>
			<slash:comments>4</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>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>Unorthodox checkbox usage</title>
		<link>https://undocumentedmatlab.com/articles/unorthodox-checkbox-usage?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=unorthodox-checkbox-usage</link>
					<comments>https://undocumentedmatlab.com/articles/unorthodox-checkbox-usage#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 14 Jan 2015 21:41:18 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[UI controls]]></category>
		<category><![CDATA[Optical illusion]]></category>
		<category><![CDATA[uicontrol]]></category>
		<category><![CDATA[uisplitpane]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5457</guid>

					<description><![CDATA[<p>There are various ways to display interactive split-panes in Matlab GUI. Uiextras flex-panels override a checkbox control's CData to display a divider. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/unorthodox-checkbox-usage">Unorthodox checkbox usage</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/tri-state-checkbox" rel="bookmark" title="Tri-state checkbox">Tri-state checkbox </a> <small>Matlab checkboxes can easily be made to support tri-state functionality....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/profiling-matlab-memory-usage" rel="bookmark" title="Profiling Matlab memory usage">Profiling Matlab memory usage </a> <small>mtic and mtoc were a couple of undocumented features that enabled users of past Matlab releases to easily profile memory usage. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/transparency-in-uicontrols" rel="bookmark" title="Transparency in uicontrols">Transparency in uicontrols </a> <small>Matlab uicontrols' CData property can be customized to provide background transparency....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-listbox-editbox-scrollbars" rel="bookmark" title="Customizing listbox &amp; editbox scrollbars">Customizing listbox &amp; editbox scrollbars </a> <small>Matlab listbox and multi-line editbox uicontrols have pre-configured scrollbars. This article shows how they can be customized....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A few weeks ago, Robert Cumming <a target="_blank" href="/articles/transparency-in-uicontrols">explained</a> how we can use a Matlab uicontrol&#8217;s <b>CData</b> property to provide an optical illusion of a transparent background. Today I will discuss another usage of this property, providing a simple checkbox control the unorthodox appearance of a split-pane divider.<br />
The underlying problem description is easy: we wish to have the ability to split a Matlab uipanel into two or more sub-panels, separated by a draggable horizontal/vertical divider. Such split-panes are standard in any semi-decent GUI, but for some reason were never incorporated in official Matlab. This is a real pity, but not to worry as there are at least two alternatives we could use:</p>
<h3 id="UISplitPane">UISplitPane</h3>
<p><i><b>UISplitPane</b></i> is a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/23073-uisplitpane-split-a-container--figure-frame-uipanel--into-two-resizable-sub-containers">utility</a> that I wrote back in 2009 that uses a Java <code><a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/tutorial/uiswing/components/splitpane.html">JSplitPane</a></code> divider and associates it with plain Matlab panels on both sides. This solves the problem of embedding Matlab axes in Java panels, such as the ones provided by the standard Java <code>JSplitPane</code>. A detailed description of the technique can be found in my <a target="_blank" href="/articles/uisplitpane">dedicated post</a> on this utility.<br />
<figure id="attachment_120" aria-describedby="caption-attachment-120" style="width: 400px" class="wp-caption alignright"><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/blog/wp-content/uploads/2009/03/uisplitpane_animated.gif" alt="Two levels of UISplitPane, with customized dividers" title="Two levels of UISplitPane, with customized dividers" width="400" height="354" class="size-full wp-image-120" /><figcaption id="caption-attachment-120" class="wp-caption-text">Two levels of UISplitPane, with customized dividers</figcaption></figure></p>
<pre lang='matlab'>[hDown,hUp,hDiv1] = uisplitpane(gcf, 'Orientation','ver', 'dividercolor',[0,1,0]);
[hLeft,hRight,hDiv2] = uisplitpane(hDown, 'dividercolor','r', 'dividerwidth',3);
t=0:.1:10;
hax1=axes('Parent',hUp);    plot(t,sin(t));
hax2=axes('parent',hLeft);  plot(t,cos(t));
hax3=axes('parent',hRight); plot(t,tan(t));
hDiv1.DividerLocation = 0.75;    % one way to modify divider properties...
set(hDiv2,'DividerColor','red'); % ...and this is another way...
</pre>
<p><span id="more-5457"></span><br />
Making <i><b>UISplitPane</b></i> work in HG2 (R2014b onward) was quite a pain: numerous changes had to be made. For example, dynamic UDD properties can no longer be added to Matlab handles, only to Java ones. For Matlab handles, we now need to use the <i><b>addprop</b></i> function. For such properties, the UDD meta-property <code>SetFunction</code> is now called <code>SetMethod</code> (and similarly for Get) and only accepts function handles (not function handle cells as in UDD). Also, the UDD meta-property <code>AccessFlags.PublicSet='off'</code> needed to change to <code>SetAccess='private'</code>. Also, <b><i>handle.listener</b></i> no longer works; instead, we need to use the <i><b>addlistener</b></i> function. There are quite a few other similar tweaks, but <i><b>UISplitPane</b></i>now hopefully works well on both old (HG1, R2014a and earlier) and new (HG2, R2014b+) Matlab releases. Let me know if you still see unhandled issues.</p>
<h3 id="uiextras">UIExtras flex-box</h3>
<p>UIExtras (officially named &#8220;GUI Layout Toolbox&#8221;) is a toolbox of very useful GUI handling functions related to layout management. Written within MathWorks and originally posted in 2010, it has been under continuous maintenance ever since. While being called a &#8220;toolbox&#8221;, it is in fact freely-downloadable from the Matlab File Exchange.<br />
The new HG2 introduced in R2014b did not just make code porting difficult for me &#8211; uiextras&#8217; developers (MathWorkers Ben Tordoff and David Sampson) also encountered great difficulties in porting the code and making sure that it is backward compatible with HG1. In the end they gave up and we now have two distinct versions of the toolbox: the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/27758-gui-layout-toolbox">original version for HG1</a> (R2014a and earlier) and a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/47982-gui-layout-toolbox">new version for HG2</a> (R2014b+).<br />
In my opinion, uiextras is one of the greatest examples of Matlab code on the File Exchange. It is well-written, well-documented and highly performant (although I would also have preferred it to be a bit more robust, it sometimes complains when used). Readers could benefit greatly by studying its techniques, and today&#8217;s subject topic is one such example. Specifically, the split-pane divider in uiextras (used by HBoxFlex and VBoxFlex) is simply a Matlab uicontrol having a custom <b>CData</b> property. This <b>CData</b> value is computed and set programmatically (at the bottom of <i><b><a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/47982-gui-layout-toolbox/content//layout/+uix/Divider.m">uix.Divider</a></b></i>) to display a flat color with some markings at the center (&#8220;hand-holds&#8221;, a visual cue for interactive dragging, which can be turned off if requested). Thus, for a vertical divider (for an HBoxFlex container) of height 100 pixels and width of 5 pixels, we would get a <b>CData</b> of 100x5x3 (x3 for RGB colors):</p>
<pre lang='matlab'>
hHBox = uiextras.HBoxFlex('Spacing',6, 'BackgroundColor','b');  % Spacing=6 means divider width =6px, and CData width =5px
hLeft  = uicontrol('parent',hHBox, 'style','check', 'string','Left split pane');
hRight = uicontrol('parent',hHBox, 'style','radio', 'string','Right split pane');
</pre>
<p><center><figure style="width: 335px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="UIExtras HBoxFlex with draggable split-pane divider" src="https://undocumentedmatlab.com/images/UIExtras_HBoxFlex.png" title="UIExtras HBoxFlex with draggable split-pane divider" width="335" height="190" /><figcaption class="wp-caption-text">UIExtras HBoxFlex with draggable split-pane divider</figcaption></figure></center><br />
The divider handle is a private property, so we cannot readily access it. However, as I have <a target="_blank" href="/articles/accessing-private-object-properties">explained</a> last year, we can use the builtin <i><b>struct</b></i> function:</p>
<pre lang='matlab'>
oldWarn = warning('off','MATLAB:structOnObject');  % temporarily disable warning message on discouraged usage
hHBox_data = struct(hHBox);  % this includes hidden/private properties
warning(oldWarn);
hDividers = hHBox_data.Dividers;  % multiple dividers are possible in HBoxFlex/VBoxFlex
cdata = get(hDividers(1), 'CData');
</pre>
<p>A very nice trick here is that this divider uicontrol is <i>not</i> a pushbutton as we might have expected. Instead, it is a checkbox control. And while it does not look anything like a standard checkbox (due to the custom <b>CData</b>), checkboxes (and radio-buttons) have a very important advantage that caused them to be preferable over buttons: in buttons, there is always a small border showing at the control&#8217;s edges, but checkboxes do not have any 3D appearance, or in other words they do not have a border &#8212; their <b>CData</b> can span the entire extent of the control. Neat, right?<br />
This enables us to customize the appearance of checkboxes (and radios) to any arbitrary shape, by setting the relevant <b>CData</b> pixels to transparent/bgcolor (as Robert showed last week for buttons). Matlab GUI controls no longer need to look a boring rectangle. We can have clickable stars, draggable icons, and other similar uses. This really opens up the possibilities for rich GUI appearance. If anyone uses this feature, please do post a comment below (preferably with a nice screenshot!).</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/unorthodox-checkbox-usage">Unorthodox checkbox usage</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/tri-state-checkbox" rel="bookmark" title="Tri-state checkbox">Tri-state checkbox </a> <small>Matlab checkboxes can easily be made to support tri-state functionality....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/profiling-matlab-memory-usage" rel="bookmark" title="Profiling Matlab memory usage">Profiling Matlab memory usage </a> <small>mtic and mtoc were a couple of undocumented features that enabled users of past Matlab releases to easily profile memory usage. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/transparency-in-uicontrols" rel="bookmark" title="Transparency in uicontrols">Transparency in uicontrols </a> <small>Matlab uicontrols' CData property can be customized to provide background transparency....</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-listbox-editbox-scrollbars" rel="bookmark" title="Customizing listbox &amp; editbox scrollbars">Customizing listbox &amp; editbox scrollbars </a> <small>Matlab listbox and multi-line editbox uicontrols have pre-configured scrollbars. This article shows how they can be customized....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/unorthodox-checkbox-usage/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Property value change listeners</title>
		<link>https://undocumentedmatlab.com/articles/property-value-change-listeners?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=property-value-change-listeners</link>
					<comments>https://undocumentedmatlab.com/articles/property-value-change-listeners#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 13 Aug 2014 14:12:55 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Listeners]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[HG2]]></category>
		<category><![CDATA[schema.prop]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4955</guid>

					<description><![CDATA[<p>HG handle property changes can be trapped in a user-defined callback. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/property-value-change-listeners">Property value change listeners</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/udd-events-and-listeners" rel="bookmark" title="UDD Events and Listeners">UDD Events and Listeners </a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/copyobj-behavior-change-in-hg2" rel="bookmark" title="copyobj behavior change in HG2">copyobj behavior change in HG2 </a> <small>the behavior of Matlab's copyobj function changed in R2014b (HG2), and callbacks are no longer copied. ...</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>
<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>For performance reasons, it is almost always better to respond to events (<i>asynchronously</i>), than to continuously check a property value (<i>synchronous polling</i>). Therefore, if we wish to do something when some property value is changed (e.g., log the event, shut down the system, liquidate the portfolio, call the police, &#8230;), then it is preferable to attach a property-change listener callback.<br />
The standard (documented) way of attaching a value-change listener to Matlab class properties is via the <i><b><a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/handle.addlistener.html">addlistener</a></b></i> function. This only works for handle (not value) classes, and only to those properties that have the <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/matlab_oop/listening-for-changes-to-property-values.html#brkimdj-1"><b>SetObservable</b> and/or <b>GetObservable</b> attribute turned on</a>:</p>
<pre lang='matlab'>addlistener(hClassObject, propertyName, 'PostSet', @myCallbackFcn);</pre>
<p>This is all nice and well for Matlab class properties, but what about HG (handle Graphics: plots &#038; GUI) properties? Can we similarly listen to changes in (say) the axes limits? Until now this has been possible, but undocumented. For example, this will trigger <i>myCallbackFcn(hAxes,eventData)</i> whenever the axes limits change (due to zoom, pan, plotting etc.):</p>
<pre lang='matlab'>
addlistener(gca, 'YLim', 'PostSet', @(hAxes,eventData) myCallbackFcn(hAxes,eventData));
% Or (shorter equivalent):
addlistener(gca, 'YLim', 'PostSet', @myCallbackFcn);
</pre>
<p>This could be very useful when such properties could be modified from numerous different locations. Rather than updating all these location to call the relevant callback function directly, we simply attach the callback to the property-change listener. It could also be useful in cases where for some reason we cannot modify the source of the update (e.g., third-party or legacy code).<br />
In addition to <code>PostSet</code>, we could also set listeners for <code>PreSet</code>. Also, we could set listeners on <code>PostGet</code> and <code>PreGet</code> &#8211; this could be useful for calculating dynamic (dependent) property values.<br />
<span id="more-4955"></span></p>
<h3 id="under-the-hood">Under the hood</h3>
<p>The HG1 variant of <i><b>addlistener</b></i> is basically equivalent to the following low-level UDD-based code snippet, as <a target="_blank" href="/articles/udd-events-and-listeners">explained here</a>:</p>
<pre lang='matlab'>
% Create the listener object
hAxes = handle(gca);  % a UDD axes class object
hProp = findprop(hAxes,'YLim');  % a schema.prop class object
hListener = handle.listener(hAxes, hProp, 'PropertyPostSet', @myCallbackFcn);
% persist the listener in memory for as long as the source object (hAxes) is alive
setappdata(hAxes, 'listener__', hListener);
</pre>
<p>(in old Matlab releases, <i><b>addlistener</b></i> was a regular m-function that placed the listeners in the source handle&#8217;s <b>ApplicationData</b> property, as the code above shows; newer releases reimplemented <i><b>addlistener</b></i> as an internal built-in function and the listener is now stored somewhere in the DLL&#8217;s inaccessible memory, rather than in the <b>ApplicationData</b> property)<br />
In HG2, <i><b>handle.listener</b></i> no longer works. Fortunately, we don&#8217;t need it since we have <i><b>addlistener</b></i> that works the same way for both HG1 (UDD objects) and HG2 (MCOS objects). Kudos on the backward-compatibility aspect, MathWorks!</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/property-value-change-listeners">Property value change listeners</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/udd-events-and-listeners" rel="bookmark" title="UDD Events and Listeners">UDD Events and Listeners </a> <small>UDD event listeners can be used to listen to property value changes and other important events of Matlab objects...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/copyobj-behavior-change-in-hg2" rel="bookmark" title="copyobj behavior change in HG2">copyobj behavior change in HG2 </a> <small>the behavior of Matlab's copyobj function changed in R2014b (HG2), and callbacks are no longer copied. ...</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>
<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/property-value-change-listeners/feed</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
		<item>
		<title>uicontextmenu performance</title>
		<link>https://undocumentedmatlab.com/articles/uicontextmenu-performance?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=uicontextmenu-performance</link>
					<comments>https://undocumentedmatlab.com/articles/uicontextmenu-performance#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 02 Apr 2014 18:00:29 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Callbacks]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Robert Cumming]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4751</guid>

					<description><![CDATA[<p>Matlab uicontextmenus are not automatically deleted with their associated objects, leading to leaks and slow-downs. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uicontextmenu-performance">uicontextmenu performance</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/performance-scatter-vs-line" rel="bookmark" title="Performance: scatter vs. line">Performance: scatter vs. line </a> <small>In many circumstances, the line function can generate visually-identical plots as the scatter function, much faster...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/zero-testing-performance" rel="bookmark" title="Zero-testing performance">Zero-testing performance </a> <small>Subtle changes in the way that we test for zero/non-zero entries in Matlab can have a significant performance impact. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/performance-accessing-handle-properties" rel="bookmark" title="Performance: accessing handle properties">Performance: accessing handle properties </a> <small>Handle object property access (get/set) performance can be significantly improved using dot-notation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/callback-functions-performance" rel="bookmark" title="Callback functions performance">Callback functions performance </a> <small>Using anonymous functions in Matlab callbacks can be very painful for performance. Today's article explains how this can be avoided. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I would like to introduce guest blogger Robert Cumming, an <a target="_blank" rel="nofollow" href="http://www.matpi.com">independent contractor</a> based in the UK who has recently worked on certification of the newest advanced civil aircraft. Today Robert will discuss the performance of <b>uicontextmenu</b>s in interactive GUIs, which were used extensively in flight test analysis.</i><br />
Have you ever noticed that a GUI slows down over time?  I was responsible for designing a highly complex interactive GUI, which plotted flight test data for engineers and designers to analyze data for comparison with pre-flight predictions. This involved extensive plotting of data (pressure, forces/moments, anemometry, actuator settings etc&#8230;.), where individual data points were required to have specific/customizable uicontextmenus.<br />
Matlab&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/ref/uicontextmenu.html">documentation on uicontextmenus</a> discusses adding them to plots, but makes no mention of the cleaning up afterwards.<br />
Let&#8217;s start with some GUI basics. First we create a figure with a simple axes and a line:</p>
<pre lang='matlab'>
x = [-10:0.2:10];
y = x.^2;
h = figure;
ax = axes ( 'parent',h );
hplot = plot ( ax, x, y );
</pre>
<p>Adding a uicontextmenu to the plot creates extra objects:</p>
<pre lang='matlab'>
uic = uicontextmenu;
uimenu ( uic, 'Label','Menu A.1' );
set ( hplot, 'uicontextmenu',uic );
fprintf ( 'Figure (h) has %i objects\n', length ( findobj ( h ) ) );
</pre>
<p>In this instance there are 5 objects, the individual menu and uicontextmenu have created an additional 2 objects.  All of this is quite basic as you would expect.<br />
<center><figure style="width: 250px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Basic plot with a custom context menu" src="https://undocumentedmatlab.com/images/uicontextmenu1.png" title="Basic plot with a custom context menu" width="250" height="170" /><figcaption class="wp-caption-text">Basic plot with a custom context menu</figcaption></figure></center><br />
<span id="more-4751"></span><br />
We now clear the plot using <i><b>cla</b></i> and draw a new line with its own new uicontextmenu. Note that we don&#8217;t save the plot handle this time:</p>
<pre lang='matlab'>
cla ( ax );
uic = uicontextmenu;
uimenu ( uic, 'Label','Menu B.1' );
plot ( ax, x, -y , 'uicontextmenu',uic );
fprintf ( 'Figure (h) has %i objects\n', length ( findobj ( h ) ) );
</pre>
<p><center><figure style="width: 250px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Another basic plot with a new context menu" src="https://undocumentedmatlab.com/images/uicontextmenu2.png" title="Another basic plot with a new context menu" width="250" height="170" /><figcaption class="wp-caption-text">Another basic plot with a new context menu</figcaption></figure></center><br />
This time the <i><b>fprintf</b></i> line tells us that the figure has 7 objects. This may not have been expected, as the first plot was cleared and the original context menu is no longer accessible (<i><b>cla</b></i> removed the plot and the line object hplot).<br />
Let&#8217;s check these object handles:</p>
<pre lang='matlab'>
>> ishandle ( findobj( h ) )'
ans =
     1     1     1     1     1     1     1     1     1     1     1     1     1
</pre>
<p>We see that all the objects are valid handles. At first this may perhaps appear confusing: after all, the plot with &#8220;Menu A.1&#8221; was deleted. Let&#8217;s check this:</p>
<pre lang='matlab'>
>> ishandle ( hplot )
ans =
     0
>> get(hplot)
Error using handle.handle/get
Invalid or deleted object.
</pre>
<p>So it appears that although the plot line was indeed deleted, its associated context menu was not. The reason for this is that the context menu is created as a child of the figure window, not the plot. We are simply using the plot line&#8217;s <b>UIContextMenu</b> property to allow the user to obtain access to it and its associated menus.<br />
Once we understand this we can do two things:</p>
<ol>
<li>Use the same uicontextmenu for each plot</li>
<li>Built individual uicontextmenus for each plot, but remember to clean up afterwards</li>
</ol>
<h3 id="importance">Is this really such a big issue?</h3>
<p>You may be wondering how big a problem is this creation of extra objects. The answer is that for simple cases like this it is really not a big issue. But let&#8217;s consider a more realistic case where we also <a target="_blank" rel="nofollow" href="http://www.mathworks.com/help/matlab/creating_guis/writing-code-for-callbacks.html">assign callbacks</a> to the menus. First we will create a figure with an axes, for plotting on and a uicontrol edit for displaying a message:</p>
<pre lang='matlab'>
function uicontextExample
   h.main = figure;
   h.ax = axes ( 'parent',h.main, 'NextPlot','add', 'position',[0.1 0.2 0.8 0.7] );
   h.msg = uicontrol ( 'style','edit', 'units','normalized', 'position',[0.08 0.01 0.65 0.1], 'backgroundcolor','white' );
   uicontrol ( 'style','pushbutton', 'units','normalized', 'position',[0.75 0.01 0.2 0.1], 'Callback',{@RedrawX20 h}, 'string','re-draw x20' );
   redraw ( [], [], h )  % see below
end
</pre>
<p>The callback <code>redraw</code> (shown below) draws a simple curve and assigns individual uicontextmenus to each individual item in the plot. Each uicontextmenu has 12 menu items:</p>
<pre lang='matlab'>
function redraw ( obj, event, h, varargin )
   cla(h.ax);
   start = tic;
   x = -50:50;
   y = x.^2;
   for ii = 1 : length(x)
      uim = uicontextmenu ( 'parent',h.main );
      for jj = 1 : 10
         menuLabel = sprintf ( 'Menu %i.%i', ii, jj );
         uimenu ( 'parent',uim, 'Label',menuLabel, 'Callback',{@redraw h} )
      end
      xStr = sprintf ( 'X = %f', x(ii) );
      yStr = sprintf ( 'Y = %f', y(ii) );
      uimenu ( 'parent',uim, 'Label',xStr, 'Callback',{@redraw h} )
      uimenu ( 'parent',uim, 'Label',yStr, 'Callback',{@redraw h} )
      plot ( h.ax, x(ii), y(ii), 'rs', 'uicontextmenu',uim );
   end
   objs = findobj ( h.main );
   s = sprintf ( 'figure contains %i objects - drawn in %3.2f seconds', length(objs), toc(start) );
   set ( h.msg, 'string',s );
   fprintf('%s\n',s)
end
</pre>
<p>To help demonstrate the slow-down in speed, the pushbutton uicontrol will redraw the plot 20 times, and show the results from the profiler:</p>
<pre lang='matlab'>
function RedrawX20 ( obj, event, h )
   profile on
   set ( obj, 'enable','off' )
   for ii = 1 : 20
      redraw ( [], [], h );
      drawnow();
   end
   set ( obj, 'enable','on' )
   profile viewer
end
</pre>
<p>The first time we run this, on a reasonable laptop it takes 0.24 seconds to draw the figure with all the menus:<br />
<center><figure style="width: 380px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Multiple context menus assigned to individual data points" src="https://undocumentedmatlab.com/images/uicontextmenu3.png" title="Multiple context menus assigned to individual data points" width="380" height="190" /><figcaption class="wp-caption-text">Multiple context menus assigned to individual data points</figcaption></figure></center><br />
When we press the &lt;re-draw x20&gt; button we get:</p>
<pre lang='matlab'>
figure contains 2731 objects - drawn in 0.28 seconds
figure contains 4044 objects - drawn in 0.28 seconds
figure contains 5357 objects - drawn in 0.28 seconds
figure contains 6670 objects - drawn in 0.30 seconds
figure contains 7983 objects - drawn in 0.32 seconds
figure contains 9296 objects - drawn in 0.30 seconds
figure contains 10609 objects - drawn in 0.31 seconds
figure contains 11922 objects - drawn in 0.30 seconds
figure contains 13235 objects - drawn in 0.32 seconds
figure contains 14548 objects - drawn in 0.30 seconds
figure contains 15861 objects - drawn in 0.31 seconds
figure contains 17174 objects - drawn in 0.31 seconds
figure contains 18487 objects - drawn in 0.32 seconds
figure contains 19800 objects - drawn in 0.33 seconds
figure contains 21113 objects - drawn in 0.32 seconds
figure contains 22426 objects - drawn in 0.33 seconds
figure contains 23739 objects - drawn in 0.35 seconds
figure contains 25052 objects - drawn in 0.34 seconds
figure contains 26365 objects - drawn in 0.35 seconds
figure contains 27678 objects - drawn in 0.35 seconds
</pre>
<p>The run time shows significant degradation, and we have many left-over objects. The profiler output confirms where the time is being spent:<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="Profiling results - context menu creation is an evident hotspot" src="https://undocumentedmatlab.com/images/uicontextmenu4.png" title="Profiling results - context menu creation is an evident hotspot" width="450" height="285" /><figcaption class="wp-caption-text">Profiling results - context menu creation is an evident hotspot</figcaption></figure></center><br />
As expected the menus creation takes most of the time. Note that the timing that you will get on your own computer for this example may vary and the slowdown may be less noticeable.<br />
Let&#8217;s extend the example to include extra input arguments in the callback  (in this example they are not used &#8211; but in the industrial example extra input arguments are very possible, and were required by the customer):</p>
<pre lang='matlab'>
for ii=1:length(x)
   uim = uicontextmenu ( 'parent',h.main );
   for jj = 1 : 10
      menuLabel = sprintf ( 'Menu %i.%i', ii, jj );
      uimenu ( 'parent',uim, 'Label',menuLabel, 'Callback',{@redraw h 1 0 1} )
   end
   xStr = sprintf ( 'X = %f', x(ii) );
   yStr = sprintf ( 'Y = %f', y(ii) );
   uimenu ( 'parent',uim, 'Label',xStr, 'Callback',{@redraw h 1 0 1} )
   uimenu ( 'parent',uim, 'Label',yStr, 'Callback',{@redraw h 1 0 1} )
   plot ( h.ax, x(ii), y(ii), 'rs', 'uicontextmenu',uim );
end
</pre>
<p>Re-running the code and pressing &lt;re-draw x20&gt; we get:</p>
<pre lang='matlab'>
figure contains 1418 objects - drawn in 0.29 seconds
figure contains 2731 objects - drawn in 0.37 seconds
figure contains 4044 objects - drawn in 0.48 seconds
figure contains 5357 objects - drawn in 0.65 seconds
...
figure contains 23739 objects - drawn in 4.99 seconds
figure contains 25052 objects - drawn in 5.34 seconds
figure contains 26365 objects - drawn in 5.88 seconds
figure contains 27678 objects - drawn in 6.22 seconds
</pre>
<p>Note that the 6.22 seconds is just the time that it took the last individual redraw, not the total time to draw 20 times (which was just over a minute). The profiler is again used to confirm that the vast majority of the time (57 seconds) was spent in the <i><b>uimenu</b></i> calls, mostly on line #23. In comparison, all other lines together took just 4 seconds to run.<br />
The simple act of adding extra inputs to the callback has completely transformed the speed of our code.<br />
How real is this example?<br />
In code written for a customer, the context menu had a variety of sub menus (dependent on the parameter being plotted &#8211; from 5 to ~20), and they each had multiple parameters passed into the callbacks. Over a relatively short period of time the user would cycle through a lot of data and the number of uicontextmenus being created was surprisingly large. For example, users would easily look at 100 individual sensors recorded at 10Hz for 2 minutes (100*10*60*2). If all sensors and points are plotted individually that would be 120,000 uicontextmenus!</p>
<h3 id="solution">So how do we resolve this?</h3>
<p>The problem is addressed by simply deleting the context menu handles once they are no longer needed. This can be done by adding a <i><b>delete</b></i> command after <i><b>cla</b></i> at the top of the <code>redraw</code> function, in order to remove the redundant uicontextmenus:</p>
<pre lang='matlab' highlight='3'>
function redraw ( obj, event, h, varargin )
   cla(h.ax);
   delete ( findobj ( h.main, 'type','uicontextmenu' ) )
   set ( h.msg, 'string','redrawing' );
   start = tic;
   ...
</pre>
<p>If we now click &lt;redraw x20&gt; we see that the number of objects and the time to create them remain its essentially the same as the first call: 1418 objects and 0.28 seconds:</p>
<pre lang='matlab'>
figure contains 1418 objects - drawn in 0.28 seconds
figure contains 1418 objects - drawn in 0.30 seconds
figure contains 1418 objects - drawn in 0.33 seconds
figure contains 1418 objects - drawn in 0.29 seconds
figure contains 1418 objects - drawn in 0.29 seconds
...
</pre>
<p>Advanced users could use <a target="_blank" href="/articles/udd-events-and-listeners/">handle listeners</a> to attached a callback such that when a plot element is deleted, so too are its associated context menus.</p>
<h3 id="conclusions">Conclusions</h3>
<p>Things to consider with uicontextmenus:</p>
<ol>
<li>Always delete uicontextmenus that you have finished with.</li>
<li>If you have multiple uicontextmenus  you will want to only delete the ones associated with the axes being cleared &#8211; otherwise you will delete more than you want to.</li>
<li>Try to reduce the number of input arguments to your callbacks, group into a structure or cell array.</li>
<li>Re-use uicontextmenus where possible.</li>
</ol>
<p>Have you had similar experiences?  Or other issues where GUI slow down over time? If so, please leave a comment below.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/uicontextmenu-performance">uicontextmenu performance</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/performance-scatter-vs-line" rel="bookmark" title="Performance: scatter vs. line">Performance: scatter vs. line </a> <small>In many circumstances, the line function can generate visually-identical plots as the scatter function, much faster...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/zero-testing-performance" rel="bookmark" title="Zero-testing performance">Zero-testing performance </a> <small>Subtle changes in the way that we test for zero/non-zero entries in Matlab can have a significant performance impact. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/performance-accessing-handle-properties" rel="bookmark" title="Performance: accessing handle properties">Performance: accessing handle properties </a> <small>Handle object property access (get/set) performance can be significantly improved using dot-notation. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/callback-functions-performance" rel="bookmark" title="Callback functions performance">Callback functions performance </a> <small>Using anonymous functions in Matlab callbacks can be very painful for performance. Today's article explains how this can be avoided. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/uicontextmenu-performance/feed</wfw:commentRss>
			<slash:comments>5</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>
	</channel>
</rss>
