<?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>File Exchange &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/file-exchange/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Thu, 28 Sep 2017 13:36:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>Runtime code instrumentation</title>
		<link>https://undocumentedmatlab.com/articles/runtime-code-instrumentation?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=runtime-code-instrumentation</link>
					<comments>https://undocumentedmatlab.com/articles/runtime-code-instrumentation#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 28 Sep 2017 13:36:17 +0000</pubDate>
				<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[File Exchange]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7063</guid>

					<description><![CDATA[<p>Conditional breakpoints can be used to instrument code with user-specified code. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/runtime-code-instrumentation">Runtime code instrumentation</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/parsing-mlint-code-analyzer-output" rel="bookmark" title="Parsing mlint (Code Analyzer) output">Parsing mlint (Code Analyzer) output </a> <small>The Matlab Code Analyzer (mlint) has a lot of undocumented functionality just waiting to be used. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/running-vb-code-in-matlab" rel="bookmark" title="Running VB code in Matlab">Running VB code in Matlab </a> <small>Matlab does not natively enable running VB code, but a nice trick enables us to do just that...</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/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>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>I regularly follow the MathWorks <a href="https://blogs.mathworks.com/pick" rel="nofollow" target="_blank">Pick-of-the-Week (POTW) blog</a>. In a <a href="https://blogs.mathworks.com/pick/2017/08/11/trace-your-calls-to-your-methods" rel="nofollow" target="_blank">recent post</a>, Jiro Doke highlighted Per Isakson&#8217;s <a href="http://www.mathworks.com/matlabcentral/fileexchange/28929-tracer4m" rel="nofollow" target="_blank"><i><b>tracer4m</b></i></a> utility. Per is an accomplished Matlab programmer, who has a solid reputation in the Matlab user community for many years. His utility uses temporary conditional breakpoints to enable users to trace calls to their Matlab functions and class methods. This uses a little-known trick that I wish to highlight in this post.<br />
<center><figure style="width: 430px" class="wp-caption aligncenter"><a href="http://www.mathworks.com/matlabcentral/fileexchange/28929-tracer4m" rel="nofollow" target="_blank"><img decoding="async" alt="tracer4m utility uses conditional breakpoints that evaluate but never become live" src="https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/28929/versions/3/screenshot.png" title="tracer4m utility uses conditional breakpoints that evaluate but never become live" width="430" hight="353"/></a><figcaption class="wp-caption-text">tracer4m utility uses conditional breakpoints that evaluate but never become live</figcaption></figure></center><br />
Matlab breakpoints are documented and supported functionality, and yet their documented use is typically focused at interactive programming in the Matlab editor, or as interactive commands that are entered in the Matlab console using the set of db* functions: <i><b>dbstop</b></i>, <i><b>dbclear</b></i>, <i><b>dbstatus</b></i>, <i><b>dbstack</b></i> etc. However, nothing prevents us from using these db* functions directly within our code.<br />
<span id="more-7063"></span><br />
For example, the <i><b>dbstack</b></i> function can help us diagnose the calling tree for the current function, in order to do action A if one of the calling ancestors was FunctionX, or to do action B otherwise (for example, to avoid nested recursions).<br />
Similarly, we could add a programmatic call to <i><b>dbstop</b></i> in order to stop at a certain code location downstream (for debugging), if a certain condition happens upstream.<br />
Per extended this idea very cleverly in <i><b>tracer4m</b></i>: conditional breakpoints evaluate a string in run-time: if the result is true (non-zero) then the code run is stopped at that location, but if it&#8217;s false (or zero) then the code run continues normally. To instrument calls to specific functions, Per created a function <code>tracer()</code> that logs the function call (using <i><b>dbstack</b></i>) and always returns the value <code>false</code>. He then dynamically created a string that contains a call to this new function and used the <i><b>dbstop</b></i> function to create a conditional breakpoint based on this function, something similar to this:</p>
<pre lang="matlab">dbstop('in', filename, 'at', location, 'if', 'tracer()');</pre>
<p>We can use this same technique for other purposes. For example, if we want to do some action (not necessarily log &#8211; perhaps do something else) when a certain code point is reached. The benefit here is that we don&#8217;t need to modify the code at all &#8211; we&#8217;re adding ad-hoc code pieces using the conditional breakpoint mechanism without affecting the source code. This is particularly useful when we do not have access to the source code (such as when it&#8217;s compiled or write-protected). All you need to do is to ensure that the instrumentation function always returns <code>false</code> so that the breakpoint does not become live and for code execution to continue normally.<br />
The <i><b>tracer4m</b></i> utility is quite sophisticated in the sense that it uses <i><b>mlint</b></i> and smart <i><b>regexp</b></i> to parse the code and know which functions/methods occur on which line numbers and have which type (<a href="/articles/parsing-mlint-code-analyzer-output" target="_blank">more details</a>). In this sense, Per used undocumented functionality. I&#8217;m certain that Jiro was not aware of the dependency on undocumented features when he posted about the utility, so please don&#8217;t take this to mean that Jiro or MathWorks officially support this or any other undocumented functionality. Undocumented aspects are often needed to achieve top functionality, and I&#8217;m happy that the POTW blog highlights utilities based on their importance and merit, even if they do happen to use some undocumented aspect.<br />
<i><b>tracer4m</b></i>&#8216;s code also contains references to the <a href="/articles/undocumented-profiler-options-part-3" target="_blank">undocumented profiler option <code>-history</code></a>, but this is not in fact used by the code itself, only in comments. I use this feature in my <a href="/articles/function-call-timeline-profiling" target="_blank">profile_history utility</a>, which displays the function call/timing history in an interactive GUI window. This utility complements <i><b>tracer4m</b></i> by providing a lot more information, but this can result in a huge amount of information for large and/or long-running programs. In addition, <i><b>tracer4m</b></i> has the benefit of only logging those functions/methods that the user finds useful, rather than all the function call, which enables easier debugging when the relevant code area is known. In short, I wish I had known about <i><b>tracer4m</b></i> when I created <i><b>profile_history</b></i>. Now that I know about it, maybe I&#8217;ll incorporate some of its ideas into <i><b>profile_history</b></i> in order to make it more useful. Perhaps another moral of this is that we should actively monitor the POTW blog, because true gems are quite often highlighted there.<br />
<center><a target="_blank" href="/articles/function-call-timeline-profiling"><img decoding="async" alt="Function call timeline profiling" src="https://undocumentedmatlab.com/images/profile_history.png" title="Function call timeline profiling" width="100%" style="max-width: 658px;" /></a><br />
Function call timeline profiling</center><br />
<!-- center>[caption id="" align="aligncenter" width="500" caption="Function call timeline profiling"]<a target="_blank" href="/articles/function-call-timeline-profiling"><img fetchpriority="high" decoding="async" alt="Function call timeline profiling" src="https://undocumentedmatlab.com/images/profile_history.png" title="Function call timeline profiling" width="500" height="410" /></a>[/caption]</center --><br />
For anyone who missed the announcement in my previous post, I&#8217;m hosting a series of live <a href="/articles/advanced-matlab-online-webinars" target="_blank">webinars on advanced Matlab topics</a> in the upcoming 2 weeks &#8211; I&#8217;ll be happy if you would join.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/runtime-code-instrumentation">Runtime code instrumentation</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/parsing-mlint-code-analyzer-output" rel="bookmark" title="Parsing mlint (Code Analyzer) output">Parsing mlint (Code Analyzer) output </a> <small>The Matlab Code Analyzer (mlint) has a lot of undocumented functionality just waiting to be used. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/running-vb-code-in-matlab" rel="bookmark" title="Running VB code in Matlab">Running VB code in Matlab </a> <small>Matlab does not natively enable running VB code, but a nice trick enables us to do just that...</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/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>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/runtime-code-instrumentation/feed</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>export_fig</title>
		<link>https://undocumentedmatlab.com/articles/export_fig?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=export_fig</link>
					<comments>https://undocumentedmatlab.com/articles/export_fig#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 21 Jan 2015 18:00:02 +0000</pubDate>
				<category><![CDATA[Guest bloggers]]></category>
		<category><![CDATA[Handle graphics]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[File Exchange]]></category>
		<category><![CDATA[Oliver Woodford]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5470</guid>

					<description><![CDATA[<p>The export_fig utility enables publication-quality Matlab plotting output. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/export_fig">export_fig</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/capturing-print-events" rel="bookmark" title="Capturing print events">Capturing print events </a> <small>Matlab print events can be trapped by users to enable easy printout customization. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/multi-column-grid-legend" rel="bookmark" title="Multi-column (grid) legend">Multi-column (grid) legend </a> <small>This article explains how to use undocumented axes listeners for implementing multi-column plot legends...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-print-setup" rel="bookmark" title="Customizing print setup">Customizing print setup </a> <small>Matlab figures print-setup can be customized to automatically prepare the figure for printing in a specific configuration...</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>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><i>I would like to introduce guest blogger <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/profile/authors/1073021-oliver-woodford">Oliver Woodford</a>. For the past several years Oliver has been a top contributor on the Matlab File Exchange, and several of his utilities have earned the prestigious distinction as &#8220;Pick of the Week&#8221;. This is no easy feat in a File Exchange that hosts ~23K utilities at latest count. For the past few years, excluding short spans of time, Oliver&#8217;s <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/23629-export-fig"><b>export_fig</b></a> was the File Exchange&#8217;s most downloaded utility, by a wide margin. <b>export_fig</b> has improved the output quality of figures for so many numerous Matlab users that it is hard to imagine a Matlab File Exchange without it. Today, Oliver describes the basic technical mechanisms underlying <b>export_fig</b>.</i><br />
Yair has very kindly agreed to take over maintenance of <i><b>export_fig</b></i>. For his benefit, and anyone else&#8217;s interest, I will briefly describe the layout and functionality of the toolbox.<br />
Before starting, I always recommend that new users read the <a target="_blank" rel="nofollow" href="https://github.com/altmany/export_fig/blob/master/README.md">README file</a>, to get a better understanding of the available options, how the functions perform, how to do certain frequently-asked things, and what problems still remain. The following excerpt comes from the README file (please do read the entire file):<br />
If you&#8217;ve ever wondered what&#8217;s going on in the icon on the <i><b>export_fig</b></i> download page (reproduced below), then this explanation is for you: The icon is designed to demonstrate as many of <i><b>export_fig</b></i>&#8216;s features as possible. Given a figure containing a translucent mesh (top right), <i><b>export_fig</b></i> can export to pdf (bottom center), which allows the figure to be zoomed in without losing quality (because it&#8217;s a vector graphic), but isn&#8217;t able to reproduce the translucency, and also, depending on the viewer, creates small gaps between the patches, which are seen here as thin white lines. By contrast, when exporting to png (top left), translucency is preserved (see how the graphic below shows through), the figure is anti-aliased, but zooming-in does not reveal more detail.<br />
<center><figure style="width: 450px" class="wp-caption aligncenter"><a target="_blank" rel="nofollow" href="http://bit.ly/1yAD3o4"><img decoding="async" alt="export_fig demo usage (click for details)" src="http://bit.ly/1yAD3o4" title="export_fig demo usage (click for details)" width="450" height="318" /></a><figcaption class="wp-caption-text"><i><b>export_fig</b></i> demo usage (click for details)</figcaption></figure></center><br />
<span id="more-5470"></span></p>
<h3 id="goals">Goals of <i>export_fig</i></h3>
<ol>
<li>
<h4 id="quality">Publication quality</h4>
<p>I wrote <i><b>export_fig</b></i> to produce nice looking figures for my PhD thesis and journal papers. The two standard MATLAB functions for exporting figures are <i><b>saveas</b></i> and <i><b>print</b></i>. Unfortunately, the quality of their default outputs just wasn&#8217;t good enough. For example, images in PDF outputs would be heavily compressed and I wanted control over image quality.<br />
<i>eps2pdf</i> (which is part of the <i><b>export_fig</b></i> package) takes a quality setting as input, and converts this into suitable settings for <i>ghostscript</i> to convert the EPS file to a PDF, allowing users to get much higher fidelity output. In addition, <i>ghostscript</i> also crops the figure border to the EPS bounding box, and embeds fonts in the PDF. This last feature is obligatory for some publications, and <i><b>export_fig</b></i> is sometimes recommended by conferences or journals for this reason. Control of JPEG quality is achieved by passing the quality option to <i><b>imwrite</b></i> in <i>export_fig.m</i>.<br />
In <i>export_fig.m</i>, I also added anti-aliasing for raster outputs (by exporting at a higher resolution and downsizing), and alpha-matting (by exporting with both black and white backgrounds to compute transparency) for PNG outputs. The alpha-matting feature allows textured backgrounds to show through the exported figure, which can be useful for presentation slides. Here is an image that demonstrates such alpha-matting:<br />
<center><figure style="width: 300px" class="wp-caption aligncenter"><img decoding="async" alt="Transparency alpha-matting" src="https://undocumentedmatlab.com/images/transparency_alpha_matting.png" title="Transparency alpha-matting" width="300" height="274" /><figcaption class="wp-caption-text">Transparency alpha-matting</figcaption></figure></center>
</li>
<li>
<h4 id="WYSIWYG">WYSIWYG (<i>what you see is what you get</i>)</h4>
<p>Another issue with <i><b>saveas</b></i> and <i><b>print</b></i> is that, by default, they do not reproduce a figure exactly as it appears on screen. The dimensions change, the aspect ratio changes, the amount of whitespace changes, the background color changes, the axes ticks change, line dash lengths change, the fonts change, etc. All these changes are generally-undesirable side-effects of those functions.<br />
<i><b>export_fig</b></i> avoids these changes to the figure, ensuring that it gets exported as faithfully as possible to the on screen visualization. <i><b>export_fig</b></i> uses <i><b>print</b></i> under the hood, but changes various figure and axes settings to get the desired result. For example, in <i>export_fig.m</i> I call <code>set(fig,'InvertHardcopy','off')</code>, which ensures that the background color doesn&#8217;t change. I also set the axes Limits and Tick modes to <code>'manual'</code>, to ensure that axes don&#8217;t change. Similarly, in <i>print2eps.m</i>, I call <code>set(fig, 'PaperPositionMode','auto', 'PaperOrientation','portrait')</code> to ensure that the figure dimensions don&#8217;t change for vector outputs.<br />
Two of the changes, line dash lengths and fonts, are caused by the Painters renderer, and so they only occur in vector output. The only way to fix these issues was to edit the EPS file that <i><b>print</b></i> generates: <i>fix_lines.m</i> changes the definition of dash lengths in the EPS file, so that the dash lengths depend on the line widths. Likewise, <i>print2eps.m</i> changes unsupported fonts in the figure to supported ones, then reinserts the unsupported font into the EPS. Unfortunately this doesn&#8217;t work so well when the two fonts have different character widths.<br />
In addition to these features, the MATLAB rendering pipeline (in both HG1 and HG2 versions) is full of bugs. Many lines of code in <i><b>export_fig</b></i> are dedicated to circumventing these undocumented bugs. For example, lines 249-273 of today&#8217;s <i>export_fig.m</i>:</p>
<pre lang='matlab'>
% MATLAB "feature": black colorbar axes can change to white and vice versa!
hCB = findobj(fig, 'Type', 'axes', 'Tag', 'Colorbar');
if isempty(hCB)
    yCol = [];
    xCol = [];
else
    yCol = get(hCB, 'YColor');
    xCol = get(hCB, 'XColor');
    if iscell(yCol)
        yCol = cell2mat(yCol);
        xCol = cell2mat(xCol);
    end
    yCol = sum(yCol, 2);
    xCol = sum(xCol, 2);
end
% MATLAB "feature": apparently figure size can change when changing colour in -nodisplay mode
pos = get(fig, 'Position');
% Set the background colour to black, and set size in case it was changed internally
tcol = get(fig, 'Color');
set(fig, 'Color', 'k', 'Position', pos);
% Correct the colorbar axes colours
set(hCB(yCol==0), 'YColor', [0 0 0]);
set(hCB(xCol==0), 'XColor', [0 0 0]);
</pre>
<p>Similarly, lines <i>143-160</i> of today&#8217;s <i>print2eps.m</i>:</p>
<pre lang='matlab'>
% MATLAB bug fix - black and white text can come out inverted sometimes
% Find the white and black text
black_text_handles = findobj(fig, 'Type', 'text', 'Color', [0 0 0]);
white_text_handles = findobj(fig, 'Type', 'text', 'Color', [1 1 1]);
% Set the font colors slightly off their correct values
set(black_text_handles, 'Color', [0 0 0] + eps);
set(white_text_handles, 'Color', [1 1 1] - eps);
% MATLAB bug fix - white lines can come out funny sometimes
% Find the white lines
white_line_handles = findobj(fig, 'Type', 'line', 'Color', [1 1 1]);
% Set the line color slightly off white
set(white_line_handles, 'Color', [1 1 1] - 0.00001);
% Print to eps file
print(fig, options{:}, name);
% Reset the font and line colors
set(black_text_handles, 'Color', [0 0 0]);
set(white_text_handles, 'Color', [1 1 1]);
set(white_line_handles, 'Color', [1 1 1]);
</pre>
</li>
</ol>
<h3 id="design">Design philosophy</h3>
<p>The <i><b>export_fig</b></i> toolbox is just a collection of functions. I put code into a separate function when either:</p>
<ol>
<li>One might want to use that functionality on its own, or</li>
<li>That functionality is required by two or more other functions.</li>
</ol>
<p>Subfunctions are used for code called multiple times in only one file, or where it improves legibility of the code.<br />
The easiest way to understand the structure of the <i><b>export_fig</b></i> toolbox is to visualize the tree of function dependencies within the toolbox:<br />
<center><figure style="width: 600px" class="wp-caption aligncenter"><a target="_blank" href="/images/export_fig.png"><img loading="lazy" decoding="async" alt="export_fig overview (click for details)" src="https://undocumentedmatlab.com/images/export_fig.png" title="export_fig overview (click for details)" width="600" height="300" /></a><figcaption class="wp-caption-text"><i><b>export_fig</b></i> overview (click for details)</figcaption></figure></center><br />
I&#8217;ll now describe what each function does in a bit more detail:</p>
<ol>
<li>
<h4 id="export_fig"><i>export_fig</i></h4>
<p>This is the main function in the toolbox. It allows exporting a figure to several different file formats at once. It parses the input options. If only a subset of axes are being exported then it handles the transfer of these to a new figure (which gets destroyed at the end). It makes calls to <i>print2array()</i> for raster outputs, and <i>print2eps()</i> for vector outputs. For raster outputs, it also does the downsampling if anti-aliasing is enabled, and alphamatte computation if transparency is enabled. For vector outputs, it also does the conversion from eps to pdf, and also pdf back to eps. The reason for this last conversion is that the pdf is cropped, compressed and has the fonts embedded, and eps outputs should get this too (though I don&#8217;t think the font embedding remains).</li>
<li>
<h4 id="print2array"><i>print2array</i></h4>
<p>This function rasterizes the figure. If the painters algorithm is specified then it calls <i>print2eps()</i>, then rasterizes the resulting EPS file using ghostscript. If another renderer is specified then this function just calls <i><b>print</b>()</i> to output a bitmap. Finally, borders are cropped, if requested.</li>
<li>
<h4 id="print2eps"><i>print2eps</i></h4>
<p>This function calls <i><b>print</b>()</i> to generate an EPS file, then makes several fixes to the EPS file, including making dash lengths commensurate with line width (old graphics system (HG1) only, i.e. R2014a or earlier), and substituting back in unsupported fonts.</li>
<li>
<h4 id="crop_borders"><i>crop_borders</i></h4>
<p>Crops away any margin space surrounding the image(s): Given an image or stack of images (stacked along the 4th dimension), and a background color, <i>crop_borders()</i> computes the number of rows at the top and bottom and number of columns on the left and the right of the image(s) that are entirely the background color, and removes these rows and columns.</li>
<li>
<h4 id="ghostscript"><i>ghostscript</i></h4>
<p>This function looks for a Ghostscript executable. or asks the user to specify its location. It then stores the path, or simply loads the path if one is already stored. It then calls the Ghostscript executable with the specified arguments.</li>
<li>
<h4 id="fix_lines"><i>fix_lines</i></h4>
<p>This function makes dash lengths commensurate with line width, and converts grid lines from dashes to circular dots, in EPS files generated by MATLAB using HG1 (R2014a or earlier). <i><b>fix_lines</b></i> is also available as a separate <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/23604-fix-lines">File Exchange utility</a> (<a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/pick/2010/01/15/fixing-postscript-lines/">selected</a> for Pick-of&#8211;the-Week, <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/pick/2010/05/28/creating-and-exporting-publication-quality-graphics/">just like</a> <i><b>export_fig</b></i>). This function is no longer required in HG2 (R2014b or newer) &#8211; see below.</li>
<li>
<h4 id="read_write_entire_textfile"><i>read_write_entire_textfile</i></h4>
<p>Does what it says, reading or writing and entire text file from/to disk to/from memory, but handles errors gracefully, not leaving files open.</li>
<li>
<h4 id="eps2pdf"><i>eps2pdf</i></h4>
<p>This function converts an EPS file into a PDF file using <a target="_blank" rel="nofollow" href="http://www.ghostscript.com">Ghostscript</a>.</li>
<li>
<h4 id="pdf2eps"><i>pdf2eps</i></h4>
<p>This function converts a PDF file into an EPS file using <i>pdftops</i>, from the <a target="_blank" rel="nofollow" href="http://www.foolabs.com/xpdf/">Xpdf package</a>.</li>
<li>
<h4 id="pdftops"><i>pdftops</i></h4>
<p>Does exactly the same thing as the <i>ghostscript</i> function, but for the <i>pdftops</i> executable instead.</li>
<li>
<h4 id="user_string"><i>user_string</i></h4>
<p>This stores or loads user-specific strings in text files. This allows user-specific values to propagate across different versions of MATLAB, whilst avoiding these values being stored in version controlled code.</li>
<li>
<h4 id="copyfig"><i>copyfig</i></h4>
<p>This function simply creates a copy of a figure, like the built-in <i><b>copyobj</b>()</i>. However, because the latter has some bugs, this function, which saves the figure to disk then opens it again, is required. Indeed, much of the code within the toolbox is simply circumventing bugs in MATLAB functions.</li>
<li>
<h4 id="isolate_axes"><i>isolate_axes</i></h4>
<p>This function removes unwanted axes from a figure. The approach to exporting a subset of axes is to copy the figure then remove the unwanted axes. Again, this is to circumvent bugs in the builtin function <i><b>copyobj</b>()</i>.</li>
<li>
<h4 id="using_hg2"><i>using_hg2</i></h4>
<p>This function provides a robust way of checking if HG2 is in use (HG1 is the default in R2014a or older; HG2 is the default in R2014b or newer).<br />
In HG2, the entire rendering pipeline has changed. While most of the features remain the same, the bugs have completely changed. For example, dash lengths in HG2 vector output are now sensible, so <i>fix_lines</i> is not required. However, in R2014b at least, patch-based graphics generate bloated EPS files, and line widths cannot go below 0.75pt. Finally, an obvious change for raster output is that it is smoothed by default, so anti-aliasing is not required; the default settings in the <i>parse_args()</i> function within <i>export_fig.m</i> reflect this.</li>
<li>
<h4 id="append_pdfs"><i>append_pdfs</i></h4>
<p><i><b>export_fig</b></i> does have a <code>-append</code> option, but this gets slower the larger the appended file becomes. A quicker way of generating a multipage PDF from several figures is to export them all to separate PDFs, then use this function to combine them into one in a single go. Also available as a separate <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/31215-append-pdfs">File Exchange utility</a>.</li>
<li>
<h4 id="im2gif"><i>im2gif</i></h4>
<p>This function converts a stack of images, or a multi-image TIFF file, to an animated GIF. <i><b>export_fig</b></i> can generate multi-image TIFFs using the <code>-append</code> option, making generating animated GIFs straightforward. Also available as a separate <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/32546-im2gif">File Exchange utility</a>.</li>
</ol>
<p>And that&#8217;s it! All the functions have help text describing their input and output arguments.</p>
<h3 id="editorial">Editorial notes</h3>
<p><i>After several year of creating, improving and maintaining <i><b>export_fig</b></i>, Oliver is unfortunately no longer able to maintain this utility. As Oliver mentioned above, I (Yair) have volunteered to try to step into his shoes and maintain it. As Oliver&#8217;s detailed description (which barely scratches the surface) shows, this is certainly not a trivial utility. It will take me some time to get up to speed with all the internal technical details, so please be patient&#8230;<br />
Readers interested in high-fidelity export might also consider using my <a target="_blank" href="/articles/screencapture-utility">ScreenCapture utility</a>. Unlike <i><b>export_fig</b></i>, which uses Matlab&#8217;s builtin <i><b>print</b></i> function to generate (and fix) the output, <i><b>ScreenCapture</b></i> uses the standard <code>java.awt.Robot.<i>createScreenCapture()</i></code> to take an actual screen-capture of the requested figure, axes or window area and then saves this to file/clipboard or sends it to the printer. In a sense, the <i><b>export_fig</b></i> and <i><b>ScreenCapture</b></i> utilities nicely complement each other.<br />
</i></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/export_fig">export_fig</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/capturing-print-events" rel="bookmark" title="Capturing print events">Capturing print events </a> <small>Matlab print events can be trapped by users to enable easy printout customization. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/multi-column-grid-legend" rel="bookmark" title="Multi-column (grid) legend">Multi-column (grid) legend </a> <small>This article explains how to use undocumented axes listeners for implementing multi-column plot legends...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-print-setup" rel="bookmark" title="Customizing print setup">Customizing print setup </a> <small>Matlab figures print-setup can be customized to automatically prepare the figure for printing in a specific configuration...</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>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/export_fig/feed</wfw:commentRss>
			<slash:comments>20</slash:comments>
		
		
			</item>
		<item>
		<title>checkClass</title>
		<link>https://undocumentedmatlab.com/articles/checkclass?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=checkclass</link>
					<comments>https://undocumentedmatlab.com/articles/checkclass#respond</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 11 Jun 2014 18:00:07 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[File Exchange]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4833</guid>

					<description><![CDATA[<p>The checkClass utility enables easy listing of Java class methods.</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/checkclass">checkClass</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/checkboxlist" rel="bookmark" title="CheckboxList">CheckboxList </a> <small>Matlab listboxes can be enhanced with checkboxes next to each item. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-combobox-popups" rel="bookmark" title="Customizing combobox popups">Customizing combobox popups </a> <small>Matlab combobox (dropdown) popups can be customized in a variety of ways. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-3" rel="bookmark" title="Customizing menu items part 3">Customizing menu items part 3 </a> <small>Matlab menu items can easily display custom icons, using just a tiny bit of Java magic powder. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-gui-display-container-hierarchy" rel="bookmark" title="FindJObj GUI &#8211; display container hierarchy">FindJObj GUI &#8211; display container hierarchy </a> <small>The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Over the past few years I have shown numerous uses of Java components in Matlab, many of them built-into the Matlab environment and can be used as-is. I have been asked many times how I uncover these components and how I discover how to use them. The short answer is that this is indeed often not easy. The blog articles (and my book) only present &#8220;<i>success stories</i>&#8220;, i.e. cases where I was able to uncover the behavior, functionality and usage of such components; they do not present the numerous other cases where I have not been so successful.<br />
Still, over the course of the past 10-15 years, I developed several tools that help me become more efficient in this work, and I&#8217;ve posted most of these on the File Exchange. I&#8217;ve already written here about the <i><b>FindJObj</b></i> utility, both as a means for <a target="_blank" href="/articles/findjobj-find-underlying-java-object">uncovering the underlying Java reference</a> of Matlab GUI controls, and as a means to <a target="_blank" href="/articles/findjobj-gui-display-container-hierarchy">visualize the GUI hierarchy</a> of a specified window or container. I also wrote about my <a target="_blank" href="/articles/uiinspect"><i><b>uiinspect</b></i> utility</a>, which analyzes the specified object in a compact and intuitive GUI window.<br />
Today I wish to complete the picture by describing my <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/26947-checkclass"><i><b>checkClass</b></i> utility</a>. <i><b>checkClass</b></i> is more limited than <i><b>uiinspect</b></i> in the types of objects that it can analyze (almost only Java objects) and the information that it presents (for example, callbacks and properties are not listed separately). <i><b>checkClass</b></i>&#8216;s main benefit is the fact that it is a very lightweight (230 lines of code), fast, GUI-less console application. <i><b>checkClass</b></i> highlights the differences between the analyzed class and its superclass, which is especially useful when investigating the functionality of objects. During the course of my work, I use checkClass for 95% of my investigations, and uiinspect/findjobj only for the remainder. For Java objects at least, a detailed console listing of the methods is quite enough, since properties are typically accessed via <i>getPropName()/setPropName()</i> accessor methods. The combination of <i><b>checkClass</b></i> and <i><b>uiinspect</b></i> can be very useful when investigating a new Java library or integrating a 3rd-party API.<br />
Here is a sample output for the <code>com.mathworks.mwswing.MJToggleButton</code> class:</p>
<div class="wp_syntax">
<div class="code">
<pre class="text" style="font-family:monospace;">
>> jButton = com.mathworks.mwswing.MJToggleButton;
>> checkClass(jButton)  <span style="color: #228B22;">% or: jButton.checkClass</span>
Class <span style="color:#0000FF;"><u>com.mathworks.mwswing.MJToggleButton</u></span> (<span style="color:#0000FF;"><u>uiinspect</u></span>)
Superclass: <span style="color:#0000FF;"><u>javax.swing.JToggleButton</u></span>
Methods in MJToggleButton missing in JToggleButton:
   hasFlyOverAppearance() : boolean
   hideText()
   isAutoMnemonicEnabled() : boolean
   isTextHidden() : boolean
   setAutoMnemonicEnabled(boolean)
   setFlyOverAppearance(boolean)
   setFocusTraversable(boolean)
   unHideText()
Methods inherited & modified by MJToggleButton:
   getForeground() : <span style="color:#0000FF;"><u>java.awt.Color</u></span>
   getParent() : <span style="color:#0000FF;"><u>java.awt.Container</u></span>
   isFocusTraversable() : boolean
   paint(<span style="color:#0000FF;"><u>java.awt.Graphics</u></span>)
   setAction(<span style="color:#0000FF;"><u>javax.swing.Action</u></span>)
   setModel(<span style="color:#0000FF;"><u>javax.swing.ButtonModel</u></span>)
   setText(<span style="color:#0000FF;"><u>java.lang.String</u></span>)
Interfaces in JToggleButton missing in MJToggleButton:
   <span style="color:#0000FF;"><u>javax.accessibility.Accessible</u></span>
Interfaces in MJToggleButton missing in JToggleButton:
   <span style="color:#0000FF;"><u>com.mathworks.mwswing.ExtendedButton</u></span>
</pre>
</div>
</div>
<p><span id="more-4833"></span><br />
The interpretation is quite intuitive. For example, <i>isTextHidden()</i> is a class method that accepts no input args and returns a boolean result; <i>setText()</i> is a method that accepts a string and returns no result.<br />
Each of the hyperlinks is linked to another <i><b>checkClass</b></i> on the specified class. This makes investigation of classes and their interconnections quite easy.<br />
From this output, we learn that the MathWorks <code>MJToggleButton</code> class added the <b>FlyOverAppearance</b> and <b>AutoMnemonicEnabled</b> properties, together with their associated accessor methods. We also learn that <code>MJToggleButton</code> added a non-property method: <i>hideText()</i>.<br />
Finally, <i>setFocusTraversable()</i> was added as a setter method to the <b>FocusTraversable</b> property: the getter method <i>isFocusTraversable()</i> is already defined in the ancestor <code><a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JToggleButton.html">JToggleButton</a></code> class (which is part of the standard Swing package) – <code>MJToggleButton</code> simply added a setter method.<br />
Some classes (e.g., <code>MJSlider</code>) appear to be plain wrappers for their Swing ancestor:</p>
<div class="wp_syntax">
<div class="code">
<pre class="text" style="font-family:monospace;">
>> checkClass(<span style="color:#A020F0;">'com.mathworks.mwswing.MJSlider'</span>)
Class <span style="color:#0000FF;"><u>com.mathworks.mwswing.MJSlider</u></span> (<span style="color:#0000FF;"><u>uiinspect</u></span>)
Superclass: <span style="color:#0000FF;"><u>javax.swing.JSlider</u></span>
Methods inherited & modified by MJSlider:
    setModel(<span style="color:#0000FF;"><u>javax.swing.BoundedRangeModel</u></span>)
Interfaces in JSlider missing in MJSlider:
    <span style="color:#0000FF;"><u>javax.accessibility.Accessible</u></span>
    <span style="color:#0000FF;"><u>javax.swing.SwingConstants</u></span>
</pre>
</div>
</div>
<p>In other cases, MathWorks has extensively modified the base class functionality:</p>
<div class="wp_syntax">
<div class="code">
<pre class="text" style="font-family:monospace;">
>> checkClass <span style="color:#A020F0;">com.mathworks.mwswing.MJToolBar</span>
Class <span style="color:#0000FF;"><u>com.mathworks.mwswing.MJToolBar</u></span> (<span style="color:#0000FF;"><u>uiinspect</u></span>)
Superclass: <span style="color:#0000FF;"><u>javax.swing.JToolBar</u></span>
Methods in MJToolBar missing in JToolBar:
   addGap()
   addGap(int)
   addToggle(<span style="color:#0000FF;"><u>javax.swing.Action</u></span>) : <span style="color:#0000FF;"><u>javax.swing.JToggleButton</u></span>
   configure(<span style="color:#0000FF;"><u>com.mathworks.mwswing.ExtendedButton</u></span>) (static)
   configureButton(<span style="color:#0000FF;"><u>com.mathworks.mwswing.MJButton</u></span>) (static)
   configureButton(<span style="color:#0000FF;"><u>com.mathworks.mwswing.MJToggleButton</u></span>) (static)
   configureButton(<span style="color:#0000FF;"><u>com.mathworks.mwswing.MJToggleButton</u></span>, boolean) (static)
   createMacPressedIcon(<span style="color:#0000FF;"><u>javax.swing.Icon</u></span>) : <span style="color:#0000FF;"><u>javax.swing.Icon</u></span> (static)
   dispose()
   dispose(<span style="color:#0000FF;"><u>javax.swing.JToolBar</u></span>) (static)
   getComponentExcludingMoreButton(int) : <span style="color:#0000FF;"><u>java.awt.Component</u></span>
   getFlyOverBorder() : <span style="color:#0000FF;"><u>javax.swing.border.Border</u></span> (static)
   getToggleFlyOverBorder() : <span style="color:#0000FF;"><u>javax.swing.border.Border</u></span> (static)
   isFloating() : boolean
   isMarkedNonEssential(<span style="color:#0000FF;"><u>javax.swing.JComponent</u></span>) : boolean (static)
   isMorePopupEnabled() : boolean
   isOnMoreMenu(<span style="color:#0000FF;"><u>java.awt.Component</u></span>) : boolean
   markAsNonEssential(<span style="color:#0000FF;"><u>javax.swing.JComponent</u></span>) (static)
   setArmed(boolean)
   setInsideToolbarBorder()
   setMorePopupEnabled(boolean)
Methods inherited & modified by MJToolBar:
   add(<span style="color:#0000FF;"><u>javax.swing.Action</u></span>) : <span style="color:#0000FF;"><u>javax.swing.JButton</u></span>
   addSeparator()
   addSeparator(<span style="color:#0000FF;"><u>java.awt.Dimension</u></span>)
   doLayout()
   getMinimumSize() : <span style="color:#0000FF;"><u>java.awt.Dimension</u></span>
   getPreferredSize() : <span style="color:#0000FF;"><u>java.awt.Dimension</u></span>
   removeAll()
Interfaces in JToolBar missing in MJToolBar:
   <span style="color:#0000FF;"><u>javax.accessibility.Accessible</u></span>
   <span style="color:#0000FF;"><u>javax.swing.SwingConstants</u></span>
Static fields in MJToolBar missing in JToolBar:
   MORE_BUTTON_NAME                  = 'MoreButton'
   MORE_MENU_INELIGIBLE_PROPERTY_KEY = 'MoreMenuIneligible'
   NON_ESSENTIAL_PROPERTY_KEY        = 'NonEssentialComponent'
Sub-classes in MJToolBar missing in JToolBar:
   <span style="color:#0000FF;"><u>com.mathworks.mwswing.MJToolBar$VisibleSeparator</u></span>
</pre>
</div>
</div>
<p>In this example, we see that the <code>MJToolBar</code> class includes 3 variants for the <i>configureButton()</i> method, and 2 variants for the <i>dispose()</i> method, accepting a different number and/or type of input parameters.<br />
Similarly, for the <code>CheckBoxList</code> class:</p>
<div class="wp_syntax">
<div class="code">
<pre class="text" style="font-family:monospace;">
>> checkClass <span style="color:#A020F0;">com.mathworks.mwswing.checkboxlist.CheckBoxList</span>
Class <span style="color:#0000FF;"><u>com.mathworks.mwswing.checkboxlist.CheckBoxList</u></span> (<span style="color:#0000FF;"><u>uiinspect</u></span>)
Superclass: <span style="color:#0000FF;"><u>com.mathworks.mwswing.MJList</u></span>
Superclass: <span style="color:#0000FF;"><u>javax.swing.JList</u></span>
Methods in JList missing in CheckBoxList:
   JList(<span style="color:#0000FF;"><u>java.lang.Object</u></span>[])
   JList(<span style="color:#0000FF;"><u>java.util.Vector</u></span>)
Methods in CheckBoxList missing in JList:
   CheckBoxList(<span style="color:#0000FF;"><u>java.util.List</u></span>)
   checkAll()
   checkIndex(int)
   checkValue(<span style="color:#0000FF;"><u>java.lang.Object</u></span>)
   constrainViewerToCellHeight() : boolean
   getCellPainter(<span style="color:#0000FF;"><u>java.lang.Integer</u></span>) : <span style="color:#0000FF;"><u>java.awt.Component</u></span>
   getCellPainter(<span style="color:#0000FF;"><u>java.lang.Object</u></span>) : <span style="color:#0000FF;"><u>java.awt.Component</u></span>
   getCellViewerOffset(<span style="color:#0000FF;"><u>java.lang.Integer</u></span>) : <span style="color:#0000FF;"><u>java.awt.Dimension</u></span>
   getCellViewerOffset(<span style="color:#0000FF;"><u>java.lang.Object</u></span>) : <span style="color:#0000FF;"><u>java.awt.Dimension</u></span>
   ...
</pre>
</div>
</div>
<p>Here we see that two superclass constructor variants (accepting an array of <code>Object</code>s or a single <code>Vector</code> object) have been replaced by a single constructor that accepts a <code>List</code> object (this is considered a bad programming practice, by the way).<br />
In this case, <code>CheckBoxList</code> extends <code>MJList</code> which is also a Matlab class, which itself extends the standard Swing <code><a target="_blank" rel="nofollow" href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JList.html">JList</a></code>. By default, <i><b>checkClass</b></i> compares the specified class object versus the nearest ancestor class that is non-MathWorks. We can modify this behavior by specifying a different super-class level:</p>
<pre lang='matlab'>
>> checkClass('com.mathworks.mwswing.checkboxlist.CheckBoxList', 1)  % compare CheckBoxList to com.mathworks.mwswing.MJList
>> checkClass('com.mathworks.mwswing.checkboxlist.CheckBoxList', 2)  % compare CheckBoxList to javax.swing.JList (=default behavior)
>> checkClass('com.mathworks.mwswing.checkboxlist.CheckBoxList', 3)  % compare CheckBoxList to javax.swing.JComponent (=JList's superclass)
>> checkClass('com.mathworks.mwswing.checkboxlist.CheckBoxList', 4)  % compare CheckBoxList to java.awt.Container (=JComponent's superclass)
% ...and so on (up to java.lang.Object, which is the base class for all Java objects)
</pre>
<p><i><b>checkClass</b></i> can inspect both class name and class objects. For example:</p>
<pre lang='matlab'>
checkClass('java.lang.String')   % class name
checkClass(javax.swing.JButton)  % class object
jButton = javax.swing.JButton('Click me!');
jButton.checkClass;  % class object
checkClass('com.mathworks.mwswing.MJToolBar')  % class-name
checkClass(com.mathworks.mwswing.MJToolBar)    % class object
checkClass(com.mathworks.mde.desk.MLDesktop.getInstance)
</pre>
<p>Class methods can also be inspected using <i><b>methodsview</b></i> or preferably <i><b>uiinspect</b></i>; properties and callbacks can be inspected by using <i><b>get</b></i>, <i><b>inspect</b></i>, or again <i><b>uiinspect</b></i>. Users may also try to search the Matlab-supplied m-files for sample usage of these classes.  For example, Matlab 7.2’s <i>uisetfont.m</i>  uses <code>com.mathworks.mwswing.MJButton</code>. Note that different Matlab releases use internal classes differently. Therefore, searching the m-file code base of different Matlab releases may yield additional clues.<br />
I encourage you to <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/26947-checkclass">download the <i><b>checkClass</b></i> utility</a> and explore its code, and I welcome your feedback.<br />
p.s. &#8211; Anyone watching the TV series &#8220;<a target="_blank" rel="nofollow" href="https://en.wikipedia.org/wiki/The_Americans_(2013_TV_series)">The Americans</a>&#8221; may have noticed that in the season finale (&#8220;<a target="_blank" rel="nofollow" href="https://en.wikipedia.org/wiki/Echo_(The_Americans)">Echo</a>&#8220;), which aired on May 21, the code listing of the Echo program, is actually that of a GUIDE-created Matlab m-file (<i>linear_array_gui</i>), plus some non-Matlab code (Ada?). Matlab&#8217;s GUIDE wasn&#8217;t available in the mid-1980s, when the story purportedly takes place, back in the days of a 640KB IBM PC with a single floppy drive, but it&#8217;s a nice anachronism. In any case the combination of the Matlab and Ada code would never have run&#8230; 🙂</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/checkclass">checkClass</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/checkboxlist" rel="bookmark" title="CheckboxList">CheckboxList </a> <small>Matlab listboxes can be enhanced with checkboxes next to each item. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-combobox-popups" rel="bookmark" title="Customizing combobox popups">Customizing combobox popups </a> <small>Matlab combobox (dropdown) popups can be customized in a variety of ways. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-menu-items-part-3" rel="bookmark" title="Customizing menu items part 3">Customizing menu items part 3 </a> <small>Matlab menu items can easily display custom icons, using just a tiny bit of Java magic powder. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/findjobj-gui-display-container-hierarchy" rel="bookmark" title="FindJObj GUI &#8211; display container hierarchy">FindJObj GUI &#8211; display container hierarchy </a> <small>The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/checkclass/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>xlswrite for Mac, Linux</title>
		<link>https://undocumentedmatlab.com/articles/xlswrite-for-mac-linux?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=xlswrite-for-mac-linux</link>
					<comments>https://undocumentedmatlab.com/articles/xlswrite-for-mac-linux#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 02 Aug 2012 09:44:35 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[File Exchange]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3041</guid>

					<description><![CDATA[<p>Several Matlab utilities enable reading/writing spreadsheet data (including XLS files) in Macs, Linux. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/xlswrite-for-mac-linux">xlswrite for Mac, Linux</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/jfreechart-graphs-and-gauges" rel="bookmark" title="JFreeChart graphs and gauges">JFreeChart graphs and gauges </a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/fixing-matlabs-actxserver" rel="bookmark" title="Fixing Matlab&#039;s actxserver">Fixing Matlab&#039;s actxserver </a> <small>Matlab's COM (ActiveX) server behavior can be fixed in a couple of useful manners. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jboost-integrating-an-external-java-library-in-matlab" rel="bookmark" title="JBoost &#8211; Integrating an external Java library in Matlab">JBoost &#8211; Integrating an external Java library in Matlab </a> <small>This article shows how an external Java library can be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-line-position-in-edit-box-uicontrol" rel="bookmark" title="Setting line position in an edit-box uicontrol">Setting line position in an edit-box uicontrol </a> <small>Matlab uicontrols have many useful features that are only available via Java. Here's how to access them....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Numerous Matlab users have <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/152206">expressed frustration</a> over the years at the fact that the <i><b>xlswrite</b></i> function, used for saving/updating Excel files, is only supported on the Windows platform. Matlab uses Excel COM to implement <i><b>xlswrite</b></i> functionality, and since COM is a Windows-specific technology, <i><b>xlswrite</b></i> does not work on non-Windows platforms.<br />
In such cases, Matlab users normally save the data into a CSV (comma-separated values) file, using the built-in <i><b>csvwrite</b></i> or <i><b>dlmwrite</b></i> functions, or File-Exchange utilities such as <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/19149-any2csv">Any2CSV</a>. This enables saving the data, but does not enable saving formatting information or graphic objects (e.g., plots or images). As a side note, <i><b>xlswrite</b></i> also does not allow saving formatting information or graphic objects, but at least on Windows we can use direct COM to add them (or use my <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/15192-officedoc">OfficeDoc</a> utility).</p>
<h3 id="Java">Java solutions for spreadsheet access</h3>
<p>Luckily, the community of Java developers, which is an order of magnitude larger than the Matlab community, has developed several utilities that we can easily use in Matlab to implement <i><b>xlswrite</b></i>&#8216;s functionality on Macs, Linux, and wherever else Matlab may run &#8211; even Windows, if we really wish. Most articles on this website that deal with Java focus on its GUI aspects, i.e., how to use Java to improve Matlab&#8217;s plain-vanilla appearance/behavior. But Java is in fact a very broad programming platform that has an enormous repository of non-GUI solutions: networking, database support, data structures, computational algorithms, etc. etc. &#8211; and a huge number of them are open-source. Unlike Java&#8217;s GUI goodies, these Java packages, being non-GUI in nature, are fully supported by Matlab.<br />
The Excel spreadsheets support, and Office support in general, is just another example of the wide range of non-GUI packages available in Java. In fact there are full-fledged Office lookalikes written in Java (most notably the open-source <a target="_blank" rel="nofollow" href="http://www.openoffice.org">OpenOffice</a>). We can either use these applications directly, or interact with them from Matlab (via Java), just as we can interact with Excel on Windows.<br />
There are several Java packages that enable reading and writing spreadsheet data, without the full-blown Office support. One such open source project is the <a target="_blank" rel="nofollow" href="http://incubator.apache.org/odftoolkit/">ODF (Open Document Foundation) Toolkit</a>, which has plenty of online resources. In 2010 a Matlab user contributed a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28411">utility</a> to use the ODF Java package for reading and writing ODF-format spreadsheets (*.ods). Other users have also <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/18222-load-open-document-spreadsheets">provided</a> ODF utilities for Matlab.<br />
Using ODF is excellent and cross-platform, but does not solve the Excel problem directly, because the ODF format is incompatible with the XLS format. We can use another open-source Java package, <a target="_blank" rel="nofollow" href="http://jexcelapi.sourceforge.net/">JExcelApi</a>, for this. JExcelApi is relatively easy to use and has several online tutorials (<a target="_blank" rel="nofollow" href="http://www.vogella.com/articles/JavaExcel/article.html">example1</a>, <a target="_blank" rel="nofollow" href="http://www.andykhan.com/jexcelapi/tutorial.html">example2</a>), although it is not as widely used as ODF.<br />
Another open-source Java package that can be used to directly read and write XLS files is <a target="_blank" rel="nofollow" href="http://poi.apache.org/">Apache POI</a>. An informal comparison of POI and JExcelApi can be found <a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/4752456/memory-efficient-java-library-to-read-excel-files">here</a>.</p>
<h3 id="xlwrite"><i><b>xlwrite</b></i></h3>
<p>Very recently, <a target="_blank" rel="nofollow" href="http://aaaic.com/Our_People.html">Marin Deresco</a> has posted a Matlab utility called <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/37560-xlwrite"><i><b>xlwrite</b></i></a> that uses JExcelApi for implementing an <i><b>xlswrite</b></i> variant that can be used on all Matlab platforms.<br />
<span id="more-3041"></span><br />
After downloading <i><b>xlwrite</b></i>, we need to add its two contained JAR files (<i>jxl.jar, MXL.jar</i>) to the Java classpath:</p>
<pre lang='matlab'>
javaaddpath('C:/Yair/Utils/JExcelAPI/jxl.jar')
javaaddpath('C:/Yair/Utils/JExcelAPI/MXL.jar')
</pre>
<p>We can now use <i><b>xlwrite</b></i> to store data in a real *.xls file:</p>
<pre lang='matlab'>xlwrite('my_data.xls', magic(3))</pre>
<p><i><b>xlwrite</b></i> has similar syntax and inputs to Matlab&#8217;s <i><b>xlswrite</b></i>. It can also write 3-d arrays (which <i><b>xlswrite</b></i> cannot), of cell and double type (the third dimension is simply stored in separate worksheets).<br />
Note: Matlab&#8217;s decimal separator is &#8216;.&#8217; &#8211; in order to be able to work with exported data on Macs, Mac users may need to change Mac decimal separator preferences. To do so you need to go to System Preferences &gt; International &gt; Formats and click on Customize button in the number zone, then type &#8216;.&#8217; in the required field.<br />
<i><b>xlwrite</b></i> is a real working solution. However, it may need further refinements, that will hopefully be added in future updates to this utility:</p>
<ul>
<li>automatically add the <i><b>javaaddpath</b></i> commands to <i><b>xlwrite</b></i> so that users won&#8217;t need to do them</li>
<li>manage Java heap space, as Java heap memory saturates for large arrays exported many times (possible memory leak)</li>
<li>format dates and strings, as all numbers appear as text in Excel</li>
<li>optimize performance (the culprit appears to be a non-vectorized <i>Cell2JavaString</i> function)</li>
<li>include formatting and other goodies that the current <i><b>xlswrite</b></i> does not</li>
</ul>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/xlswrite-for-mac-linux">xlswrite for Mac, Linux</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/jfreechart-graphs-and-gauges" rel="bookmark" title="JFreeChart graphs and gauges">JFreeChart graphs and gauges </a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/fixing-matlabs-actxserver" rel="bookmark" title="Fixing Matlab&#039;s actxserver">Fixing Matlab&#039;s actxserver </a> <small>Matlab's COM (ActiveX) server behavior can be fixed in a couple of useful manners. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jboost-integrating-an-external-java-library-in-matlab" rel="bookmark" title="JBoost &#8211; Integrating an external Java library in Matlab">JBoost &#8211; Integrating an external Java library in Matlab </a> <small>This article shows how an external Java library can be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-line-position-in-edit-box-uicontrol" rel="bookmark" title="Setting line position in an edit-box uicontrol">Setting line position in an edit-box uicontrol </a> <small>Matlab uicontrols have many useful features that are only available via Java. Here's how to access them....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/xlswrite-for-mac-linux/feed</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
		<item>
		<title>Specialized Matlab plots</title>
		<link>https://undocumentedmatlab.com/articles/specialized-matlab-plots?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=specialized-matlab-plots</link>
					<comments>https://undocumentedmatlab.com/articles/specialized-matlab-plots#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 11 Apr 2012 17:25:15 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[File Exchange]]></category>
		<category><![CDATA[JFreeChart]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2849</guid>

					<description><![CDATA[<p>The new MathWorks Plot Gallery provides access to some plotting examples on the File Exchange. Numerous others are available, extending the customizability of Matlab graphics. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/specialized-matlab-plots">Specialized Matlab plots</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots" rel="bookmark" title="Customizing contour plots">Customizing contour plots </a> <small>Contour labels, lines and fill patches can easily be customized in Matlab HG2. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-histogram-plots" rel="bookmark" title="Customizing histogram plots">Customizing histogram plots </a> <small>Basic bar charts and histogram plots can be customized in important aspects. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part2" rel="bookmark" title="Customizing contour plots part 2">Customizing contour plots part 2 </a> <small>Matlab contour labels' color and font can easily be customized. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part-2" rel="bookmark" title="Customizing contour plots part 2">Customizing contour plots part 2 </a> <small>The contour lines of 3D Matlab plot can be customized in many different ways. This is the 2nd article on this issue. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A few weeks ago, MathWorks has added a new section on its website called the &#8220;<a target="_blank" rel="nofollow" href="http://www.mathworks.com/discovery/gallery.html">Plot Gallery</a>&#8220;. This section highlights specialized Matlab plots that were posted on the Matlab File Exchange (FEX) and can be used by Matlab users in their GUIs. Unfortunately, for the moment this list only includes some 20 customized plots posted by MathWorks employees, in addition to some 50 examples of using the standard Matlab plots. I have a suspicion that one day, if this proves popular, we will find the gallery integrated in the main Matlab Desktop, possibly next to the current <a target="_blank" href="/articles/plot-type-selection-components/">plot selector component</a>.<br />
Since the Plot Gallery section is a new effort at reducing plotting complexity to Matlab users, I think that it should be encouraged by user feedback. Please feel free to leave them a comment with your feedback, either <a href="/articles/specialized-matlab-plots/#respond">on this page</a>, or on their semi-official blog <a target="_blank" rel="nofollow" href="http://blogs.mathworks.com/pick/2012/03/23/matlab-plot-gallery/">announcement page</a>.<br />
My personal beef with the new Plot Gallery is the fact that it does not currently include user submissions. FEX actually contains numerous user-submitted specialized plotting utilities, answering a wide variety of needs in multiple discipline fields. These can easily be found using FEX&#8217;s search functionality or tags. For example, <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/?term=tag%3A%22plot%22">the FEX &#8220;plot&#8221; tag</a> currently has 440 separate submissions. Perhaps one day these user submissions will be added to the Plot Gallery in some searchable structured manner.<br />
One set of specialized plots that I&#8217;d like to highlight today is based on the open-source JFreeChart, that I have <a target="_blank" href="/articles/jfreechart-graphs-and-gauges/">described here</a> last year. Sven Körner has used this to <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A92825+JFreeChart">provide</a> a dozen different customized Matlab plots, a few of which can be seen below, showing the power of integrating external code in Matlab GUI. JFreeChart contains many more customizable chart, plot and gauge types so Sven&#8217;s examples should merely be considered as appetizers:<br />
<center><figure style="width: 300px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="MATLAB-integrated dial gauge chart" src="https://undocumentedmatlab.com/images/dialdemo4_300.jpg" title="MATLAB-integrated dial gauge chart" width="300" height="407"/><figcaption class="wp-caption-text">MATLAB-integrated dial gauge chart</figcaption></figure><br />
<figure style="width: 400px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" alt="MATLAB-integrated multi-axes chart" src="https://undocumentedmatlab.com/images/multipleAxis_400.jpg" title="MATLAB-integrated multi-axes chart" width="400" height="406"/><figcaption class="wp-caption-text">MATLAB-integrated multi-axes chart</figcaption></figure><br />
</center></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/specialized-matlab-plots">Specialized Matlab plots</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots" rel="bookmark" title="Customizing contour plots">Customizing contour plots </a> <small>Contour labels, lines and fill patches can easily be customized in Matlab HG2. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-histogram-plots" rel="bookmark" title="Customizing histogram plots">Customizing histogram plots </a> <small>Basic bar charts and histogram plots can be customized in important aspects. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part2" rel="bookmark" title="Customizing contour plots part 2">Customizing contour plots part 2 </a> <small>Matlab contour labels' color and font can easily be customized. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/customizing-contour-plots-part-2" rel="bookmark" title="Customizing contour plots part 2">Customizing contour plots part 2 </a> <small>The contour lines of 3D Matlab plot can be customized in many different ways. This is the 2nd article on this issue. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/specialized-matlab-plots/feed</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
