<?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>Book &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/book/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Sun, 25 Dec 2022 16:16:47 +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>Convolution performance</title>
		<link>https://undocumentedmatlab.com/articles/convolution-performance?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=convolution-performance</link>
					<comments>https://undocumentedmatlab.com/articles/convolution-performance#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 03 Feb 2016 19:00:35 +0000</pubDate>
				<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pure Matlab]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=6256</guid>

					<description><![CDATA[<p>Matlab's internal implementation of convolution can often be sped up significantly using the Convolution Theorem. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/convolution-performance">Convolution 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/plot-performance" rel="bookmark" title="Plot performance">Plot performance </a> <small>Undocumented inner plot mechanisms can significantly improve plotting performance ...</small></li>
<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/preallocation-performance" rel="bookmark" title="Preallocation performance">Preallocation performance </a> <small>Preallocation is a standard Matlab speedup technique. Still, it has several undocumented aspects. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>MathWorks&#8217; latest <a href="http://mathworks.com/company/digest/current/" rel="nofollow" target="_blank">MATLAB Digest</a> (January 2016) featured my book &#8220;<a href="/books/matlab-performance" target="_blank">Accelerating MATLAB Performance</a>&#8220;. I am deeply honored and appreciative of MathWorks for this.</p>
<p><span class="alignright"><a target="_blank" rel="nofollow" href="/books/matlab-performance"><img fetchpriority="high" decoding="async" title="Accelerating MATLAB Performance book" src="https://undocumentedmatlab.com/images/K21680-cover-3D-320x454b.jpg" alt="Accelerating MATLAB Performance book" width="320" height="454"/></a></span>I would like to dedicate today&#8217;s post to a not-well-known performance trick from my book, that could significantly improve the speed when computing the <a href="https://en.wikipedia.org/wiki/Convolution" rel="nofollow" target="_blank">convolution</a> of two data arrays. Matlab&#8217;s internal implementation of convolution (<i><b>conv</b></i>, <i><b>conv2</b></i> and <i><b>convn</b></i>) appears to rely on a sliding window approach, using implicit (internal) multithreading for speed.</p>
<p>However, this can often be sped up significantly if we use the <a href="https://en.wikipedia.org/wiki/Convolution_theorem" rel="nofollow" target="_blank">Convolution Theorem</a>, which states in essence that <i><b>conv</b>(a,b) = <b>ifft</b>(<b>fft</b>(a,N) .* <b>fft</b>(b,N))</i>, an idea <a href="http://www.mathworks.com/matlabcentral/fileexchange/24504-fft-based-convolution" rel="nofollow" target="_blank">proposed by Bruno Luong</a>. In the following usage example we need to remember to zero-pad the data to get comparable results:</p>
<pre lang="matlab">
% Prepare the input vectors (1M elements each)
x = rand(1e6,1);
y = rand(1e6,1);

% Compute the convolution using the builtin conv()
tic, z1 = conv(x,y); toc
 => Elapsed time is 360.521187 seconds.

% Now compute the convolution using fft/ifft: 780x faster!
n = length(x) + length(y) - 1;  % we need to zero-pad
tic, z2 = ifft(fft(x,n) .* fft(y,n)); toc
 => Elapsed time is 0.463169 seconds.

% Compare the relative accuracy (the results are nearly identical)
disp(max(abs(z1-z2)./abs(z1)))
 => 2.75200348450538e-10
</pre>
<p>This latest result shows that the results are nearly identical, up to a tiny difference, which is certainly acceptable in most cases when considering the enormous performance speedup (780x in this specific case). Bruno&#8217;s implementation (<i><b><a href="http://www.mathworks.com/matlabcentral/fileexchange/24504-fft-based-convolution" rel="nofollow" target="_blank">convnfft</a></b></i>) is made even more efficient by using MEX in-place data multiplications, power-of-2 FFTs, and use of GPU/Jacket where available.</p>
<p>It should be noted that the builtin Matlab functions can still be faster for relatively small data arrays, or if your machine has a large number of CPU cores and free memory that Matlab&#8217;s builtin <i><b>conv*</b></i> functions can utilize, and of course also depending on the Matlab release. So, your mileage might well vary. But given the significant speedup potential, I contend that you should give it a try and see how well it performs on your specific system and data.</p>
<p>If you have read my book, please be kind enough to post your feedback about it on Amazon (<a href="http://amazon.com/Accelerating-MATLAB-Performance-speed-programs/product-reviews/1482211297/ref=cm_cr_dp_see_all_summary" rel="nofollow" target="_blank">link</a>), for the benefit of others. Thanks in advance!</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/convolution-performance">Convolution 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/plot-performance" rel="bookmark" title="Plot performance">Plot performance </a> <small>Undocumented inner plot mechanisms can significantly improve plotting performance ...</small></li>
<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/preallocation-performance" rel="bookmark" title="Preallocation performance">Preallocation performance </a> <small>Preallocation is a standard Matlab speedup technique. Still, it has several undocumented aspects. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/convolution-performance/feed</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>New book: Accelerating MATLAB Performance</title>
		<link>https://undocumentedmatlab.com/articles/new-book-accelerating-matlab-performance?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=new-book-accelerating-matlab-performance</link>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Tue, 16 Dec 2014 21:22:03 +0000</pubDate>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[Stock Matlab function]]></category>
		<category><![CDATA[Toolbox]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[Performance]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=5391</guid>

					<description><![CDATA[<p>Accelerating MATLAB Performance (ISBN 9781482211290) is a book dedicated to improving Matlab performance (speed). </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/new-book-accelerating-matlab-performance">New book: Accelerating MATLAB 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/tips-for-accelerating-matlab-performance" rel="bookmark" title="Tips for accelerating Matlab performance">Tips for accelerating Matlab performance </a> <small>My article on "Tips for Accelerating MATLAB Performance" was recently featured in the September 2017 Matlab newsletter digest. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-java-book" rel="bookmark" title="New book: Undocumented Secrets of MATLAB-Java Programming">New book: Undocumented Secrets of MATLAB-Java Programming </a> <small>Undocumented Secrets of Matlab-Java Programming (ISBN 9781439869031) is a book dedicated to the integration of Matlab and Java. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/some-performance-tuning-tips" rel="bookmark" title="Some Matlab performance-tuning tips">Some Matlab performance-tuning tips </a> <small>Matlab can be made to run much faster using some simple optimization techniques. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-java-memory-leaks-performance" rel="bookmark" title="Matlab-Java memory leaks, performance">Matlab-Java memory leaks, performance </a> <small>Internal fields of Java objects may leak memory - this article explains how to avoid this without sacrificing performance. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>I am pleased to announce that after three years of research and hard work, following my first book on <a target="_blank" href="/books/matlab-java">Matlab-Java programming</a>, my new book &#8220;<b>Accelerating MATLAB Performance</b>&#8221; is finally published.<br />
<span class="alignright"><a target="_blank" rel="nofollow" href="http://www.crcpress.com/product/isbn/9781482211290#post-img"><img decoding="async" title="Accelerating MATLAB Performance book" src="https://undocumentedmatlab.com/images/K21680-cover-3D-320x454b.jpg" alt="Accelerating MATLAB Performance book" width="320" height="454"/></a><!-- http://www.crcpress.com/ecommerce_product/product_detail.jsf?isbn=9781482211290 --><br />
<a target="_blank" rel="nofollow" href="http://www.crcpress.com/product/isbn/9781482211290#post-banner"><img decoding="async" title="CRC discount promo code" alt="CRC discount promo code" src="https://undocumentedmatlab.com/images/CRChoriz260x69_MZK07_25perc.gif" class="aligncenter" style="margin: 10px 0 0 30px;" width="260" height="69"/></a><br />
</span> The Matlab programming environment is often perceived as a platform suitable for prototyping and modeling but not for “serious” applications. One of the main complaints is that Matlab is just too slow.<br />
<i><b>Accelerating MATLAB Performance</b></i> (<a target="_blank" rel="nofollow" href="http://www.crcpress.com/product/isbn/9781482211290#post-isbn">CRC Press, ISBN 9781482211290</a>, 785 pages) aims to correct this perception, by describing multiple ways to greatly improve Matlab program speed.<br />
The book:</p>
<ul>
<li>Demonstrates how to profile MATLAB code for performance and resource usage, enabling users to focus on the program’s actual hotspots</li>
<li>Considers tradeoffs in performance tuning, horizontal vs. vertical scalability, latency vs. throughput, and perceived vs. actual performance</li>
<li>Explains generic speedup techniques used throughout the software industry and their adaptation for Matlab, plus methods specific to Matlab</li>
<li>Analyzes the effects of various data types and processing functions</li>
<li>Covers vectorization, parallelization (implicit and explicit), distributed computing, optimization, memory management, chunking, and caching</li>
<li>Explains Matlab’s memory model and shows how to profile memory usage and optimize code to reduce memory allocations and data fetches</li>
<li>Describes the use of GPU, MEX, FPGA, and other forms of compiled code</li>
<li>Details acceleration techniques for GUI, graphics, I/O, Simulink, object-oriented Matlab, Matlab startup, and deployed applications</li>
<li>Discusses a wide variety of MathWorks and third-party functions, utilities, libraries, and toolboxes that can help to improve performance</li>
</ul>
<p>Ideal for novices and professionals alike, the book leaves no stone unturned. It covers all aspects of Matlab, taking a comprehensive approach to boosting Matlab performance. It is packed with thousands of helpful tips, code examples, and online references. Supported by this active website, the book will help readers rapidly attain significant reductions in development costs and program run times.<br />
Additional information about the book, including detailed Table-of-Contents, book structure, reviews, resources and errata list, can be found in a <a target="_blank" href="/books/matlab-performance">dedicated webpage</a> that I&#8217;ve prepared for this book and plan to maintain.<br />
<center><!-- span style="background-color:#E7E7E7;" --><b><a target="_blank" rel="nofollow" href="http://www.crcpress.com/product/isbn/9781482211290#post-cta">Click here to get your book copy now</a>!</b><br />
Use promo code  <span style="background-color: rgb(255, 255, 0);"><b>MZK07</b></span> for a 25% discount and free worldwide shipping on crcpress.com</center><br />
Instead of focusing on just a single performance aspect, I&#8217;ve attempted to cover all bases at least to some degree. The basic idea is that there are numerous different ways to speed up Matlab code: Some users might like vectorization, others may prefer parallelization, still others may choose caching, or smart algorithms, or better memory-management, or compiled C code, or improved I/O, or faster graphics. All of these alternatives are perfectly fine, and the book attempts to cover every major alternative. I hope that you will find some speedup techniques to your liking among the alternatives, and at least a few new insights that you can employ to improve your program&#8217;s speed.<br />
I am the first to admit that this book is far from perfect. There are several topics that I would have loved to explore in greater detail, and there are probably many speedup tips that I forgot to mention or have not yet discovered. Still, with over 700 pages of speedup tips, I thought this book might be useful enough as-is, flawed as it may be. After all, it will never be perfect, but I worked very hard to make it close enough, and I really hope that you&#8217;ll agree.<br />
If your work relies on Matlab code performance in any way, you might benefit by reading this book. If your organization has several people who might benefit, consider inviting me for <a target="_blank" href="/training">dedicated onsite training</a> on Matlab performance and other advanced Matlab topics.<br />
As always, your comments and feedback would be greatly welcome &#8211; please post them directly on <a href="/books/matlab-performance#respond">the book&#8217;s webpage</a>.<br />
Happy Holidays everybody!</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/new-book-accelerating-matlab-performance">New book: Accelerating MATLAB 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/tips-for-accelerating-matlab-performance" rel="bookmark" title="Tips for accelerating Matlab performance">Tips for accelerating Matlab performance </a> <small>My article on "Tips for Accelerating MATLAB Performance" was recently featured in the September 2017 Matlab newsletter digest. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-java-book" rel="bookmark" title="New book: Undocumented Secrets of MATLAB-Java Programming">New book: Undocumented Secrets of MATLAB-Java Programming </a> <small>Undocumented Secrets of Matlab-Java Programming (ISBN 9781439869031) is a book dedicated to the integration of Matlab and Java. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/some-performance-tuning-tips" rel="bookmark" title="Some Matlab performance-tuning tips">Some Matlab performance-tuning tips </a> <small>Matlab can be made to run much faster using some simple optimization techniques. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-java-memory-leaks-performance" rel="bookmark" title="Matlab-Java memory leaks, performance">Matlab-Java memory leaks, performance </a> <small>Internal fields of Java objects may leak memory - this article explains how to avoid this without sacrificing performance. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>savezip utility</title>
		<link>https://undocumentedmatlab.com/articles/savezip-utility?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=savezip-utility</link>
					<comments>https://undocumentedmatlab.com/articles/savezip-utility#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 04 Sep 2014 18:14:12 +0000</pubDate>
				<category><![CDATA[High risk of breaking in future versions]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[Performance]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4982</guid>

					<description><![CDATA[<p>Matlab data can be serialized and saved into a ZIP/GZIP file, and loaded back. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/savezip-utility">savezip utility</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/screencapture-utility" rel="bookmark" title="ScreenCapture utility">ScreenCapture utility </a> <small>The ScreenCapture utility uses purely-documented Matlab for capturing a screen region as an image from within Matlab. ...</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/improving-save-performance" rel="bookmark" title="Improving save performance">Improving save performance </a> <small>There are many different ways of improving Matlab's standard save function performance. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events" rel="bookmark" title="Matlab callbacks for Java events">Matlab callbacks for Java events </a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>A few months ago I wrote about <a target="_blank" href="/articles/serializing-deserializing-matlab-data">Matlab&#8217;s undocumented serialization/deserialization functions</a>, <i><b>getByteStreamFromArray</b></i> and <i><b>getArrayFromByteStream</b></i>. This could be very useful for both sending Matlab data across a network (thus avoiding the need to use a shared file), as well as for much faster data-save using the -V6 MAT format (<i><b>save -v6 &#8230;</b></i>).<br />
<span class="alignright"><img loading="lazy" decoding="async" src="https://undocumentedmatlab.com/images/serial2_zip.jpg" width="114" height="148"/></span> As a followup to that article, in some cases it might be useful to use ZIP/GZIP compression, rather than Matlab&#8217;s proprietary MAT format or an uncompressed byte-stream.<br />
Unfortunately, Matlab&#8217;s compression functions <i><b>zip</b></i>, <i><b>gzip</b></i> and <i><b>tar</b></i> do not really help run-time performance, but rather hurt it. The reason is that we would be paying the I/O costs three times: first to write the original (uncompressed) file, then to have <i><b>zip</b></i> or its counterparts read it, and finally to save the compressed file. <i><b>tar</b></i> is worst in this respect, since it does both a GZIP compression and a simple tar concatenation to get a standard <i>tar.gz</i> file. Using <i><b>zip/gzip/tar</b></i> only makes sense if we need to pass the data file to some external program on some remote server, whereby compressing the file could save transfer time. But as far as our Matlab program&#8217;s performance is concerned, these functions bring little value.<br />
In contrast to file-system compression, which is what <i><b>zip/gzip/tar</b></i> do, on-the-fly (memory) compression makes more sense and can indeed help performance. In this case, we are compressing the data in memory, and directly saving to file the resulting (compressed) binary data. The following example compresses <i><b>int8</b></i> data, such as the output of our <i><b>getByteStreamFromArray</b></i> serialization:<br />
<span id="more-4982"></span></p>
<pre lang='matlab'>
% Serialize the data into a 1D array of uint8 bytes
dataInBytes = getByteStreamFromArray(data);
% Parse the requested output filename (full path name)
[fpath,fname,fext] = fileparts(filepath);
% Compress in memory and save to the requested file in ZIP format
fos = java.io.FileOutputStream(filepath);
%fos = java.io.BufferedOutputStream(fos, 8*1024);  % not really important (*ZipOutputStream are already buffered), but doesn't hurt
if strcmpi(fext,'.gz')
    % Gzip variant:
    zos = java.util.zip.GZIPOutputStream(fos);  % note the capitalization
else
    % Zip variant:
    zos = java.util.zip.ZipOutputStream(fos);  % or: org.apache.tools.zip.ZipOutputStream as used by Matlab's zip.m
    ze  = java.util.zip.ZipEntry('data.dat');  % or: org.apache.tools.zip.ZipEntry as used by Matlab's zip.m
    ze.setSize(originalDataSizeInBytes);
    zos.setLevel(9);  % set the compression level (0=none, 9=max)
    zos.putNextEntry(ze);
end
zos.write(dataInBytes, 0, numel(dataInBytes));
zos.finish;
zos.close;
</pre>
<p>This will directly create a zip archive file in the current folder. The archive will contain a single entry (<i>data.dat</i>) that contains our original data. Note that <i>data.dat</i> is entirely virtual: it was never actually created, saving us its associated I/O costs. In fact we could have called it simply <i>data</i>, or whatever other valid file name.<br />
Saving to a gzip file is even simpler, since GZIP files have single file entries. There is no use for a <code>ZipEntry</code> as in zip archives that may contain multiple file entries.<br />
Note that while the resulting ZIP/GZIP file is often smaller in size than the corresponding MAT file generated by Matlab&#8217;s <i><b>save</b></i>, it is not necessarily faster. In fact, except on slow disks or network drives, <i><b>save</b></i> may well outperform this mechanism. However, in some cases, the reduced file size may save enough I/O to offset the extra processing time. Moreover, GZIP is typically much faster than either ZIP or Matlab&#8217;s <i><b>save</b></i>.</p>
<h3 id="load">Loading data from ZIP/GZIP</h3>
<p>Similar logic applies to reading compressed data: We could indeed use <i><b>unzip/gunzip/untar</b></i>, but these would increase the I/O costs by reading the compressed file, saving the uncompressed version, and then reading that uncompressed file into Matlab.<br />
A better solution would be to read the compressed file directly into Matlab. Unfortunately, the corresponding input-stream classes do not have a <i>read()</i> method that returns a byte array. We therefore use a small hack to copy the input stream into a <code>ByteArrayOutputStream</code>, using Matlab&#8217;s own stream-copier class that is used within all of Matlab&#8217;s compression and decompression functions:</p>
<pre lang='matlab'>
% Parse the requested output filename (full path name)
[fpath,fname,fext] = fileparts(filepath);
% Get the serialized data
streamCopier = com.mathworks.mlwidgets.io.InterruptibleStreamCopier.getInterruptibleStreamCopier;
baos = java.io.ByteArrayOutputStream;
fis  = java.io.FileInputStream(filepath);
if strcmpi(fext,'.gz')
    % Gzip variant:
    zis  = java.util.zip.GZIPInputStream(fis);
else
    % Zip variant:
    zis  = java.util.zip.ZipInputStream(fis);
    % Note: although the ze & fileName variables are unused in the Matlab
    % ^^^^  code below, they are essential in order to read the ZIP!
    ze = zis.getNextEntry;
    fileName = char(ze.getName);  %#ok<nasgu> => 'data.dat' (virtual data file)
end
streamCopier.copyStream(zis,baos);
fis.close;
data = baos.toByteArray;  % array of Matlab int8
% Deserialize the data back into the original Matlab data format
% Note: the zipped data is int8 => need to convert into uint8:
% Note2: see discussion with Martin in the comments section below
if numel(data) < 1e5
    data = uint8(mod(int16(data),256))';
else
    data = typecast(data, 'uint8');
end
data = getArrayFromByteStream(data);
</pre>
<p>Note that when we deserialize, we have to convert the unzipped <i><b>int8</b></i> byte-stream into a <i><b>uint8</b></i> byte-stream that <i><b>getArrayFromByteStream</b></i> can process (we don't need to do this during serialization).</p>
<h3 id="FEX">The SAVEZIP utility</h3>
<p>I have uploaded a utility called <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/47698-savezip">SAVEZIP</a> to the Matlab File Exchange which includes the <i><b>savezip</b></i> and <i><b>loadzip</b></i> functions. These include the code above, plus some extra sanity checks and data processing. Usage is quite simple:</p>
<pre lang='matlab'>
savezip('myData', magic(4))   %save data to myData.zip in current folder
savezip('myData', 'myVar')    %save myVar to myData.zip in current folder
savezip('myData.gz', 'myVar') %save data to myData.gz in current folder
savezip('data\myData', magic(4))    %save data to .\data\myData.zip
savezip('data\myData.gz', magic(4)) %save data to .\data\myData.gz
myData = loadzip('myData');
myData = loadzip('myData.zip');
myData = loadzip('data\myData');
myData = loadzip('data\myData.gz');
</pre>
<p>Jan Berling has written another variant of the idea of using <i><b>getByteStreamFromArray</b></i> and <i><b>getArrayFromByteStream</b></i> for saving/loading data from disk, in this case in an uncompressed manner. He put it all in his <i><a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/45743-bytestream-save-toolbox">Bytestream Save Toolbox</a></i> on the File Exchange.</p>
<h3 id="transmit">Transmitting compressed data via the network</h3>
<p>If instead of saving to a file we wish to transmit the compressed data to a remote process (or to save it ourselves later), we can simply wrap our <code>ZipOutputStream</code> with a <code>ByteArrayOutputStream</code>  rather than a <code>FileOutputStream</code>. For example, on the way out:</p>
<pre lang='matlab'>
baos = java.io.ByteArrayOutputStream;
if isGzipVarant
    zos = java.util.zip.GZIPOutputStream(baos);
else  % Zip variant
    zos = java.util.zip.ZipOutputStream(baos);
    ze  = java.util.zip.ZipEntry('data.dat');
    ze.setSize(numel(data));
    zos.setLevel(9);
    zos.putNextEntry(ze);
end
dataInBytes = int8(data);  % or: getByteStreamFromArray(data)
zos.write(dataInBytes,0,numel(dataInBytes));
zos.finish;
zos.close;
compressedDataArray = baos.toByteArray;  % array of Matlab int8
</pre>
<p>I leave it as an exercise to the reader to make the corresponding changes for the receiving end.</p>
<h3 id="Succinctly">New introductory Matlab book</h3>
<p>Matlab has a plethora of introductory books. But I have a special affection to one that was released only a few days ago: <i><a target="_blank" rel="nofollow" href="http://www.syncfusion.com/resources/techportal/ebooks/matlab">MATLAB Succinctly</a></i> by Dmitri Nesteruk, for which I was a technical editor/reviewer. It's a very readable and easy-to-follow book, and it's totally free, so go ahead and download.<br />
<span class="alignright"><a target="_blank" rel="nofollow" href="http://www.syncfusion.com/resources/techportal/ebooks/matlab"><img loading="lazy" decoding="async" alt="MATLAB Succinctly book by Dmitri Nesteruk" src="https://d2g29cya9iq7ip.cloudfront.net/content/images/downloads/ebooks/Matlab.png?v=01092014061434" title="MATLAB Succinctly book by Dmitri Nesteruk" width="225" height="300" /></a></span> This title adds to the large (and growing) set of free ~100-page introductory titles by <a target="_blank" rel="nofollow" href="http://www.syncfusion.com">Syncfusion</a>, on a wide variety of programming languages and technologies. Go ahead and <a target="_blank" rel="nofollow" href="http://www.syncfusion.com/resources/techportal/ebooks">download these books</a> as well. While you're at it, take a look at Syncfusion's set of professional components and spread the word. If Syncfusion gets enough income from such incoming traffic, they may continue to support their commendable project of similar free IT-related titles.<br />
This may be a good place to update that my own [second] book, <i><a target="_blank" href="/books/matlab-performance">Accelerating MATLAB Performance</a></i>, is nearing completing, and is currently in advanced copy-editing stage. It turned out that there was a lot more to Matlab performance than I initially realized. The book size (and writing time) doubled, and it turned out to be a hefty ~750 pages packed full with performance improvement tips. I'm still considering the cover image (ideas anyone?) and working on the index, but the end is now in sight. The book should be in your favorite bookstore this December. If you can't wait until then, and/or if you'd rather use the real McCoy, consider <a target="_blank" href="/consulting">inviting me</a> for a consulting session...<br />
<u><b>Addendum December 16, 2014</b></u>: I am pleased to announce that my book, <i><b>Accelerating MATLAB Performance</b></i>, is now published (<a target="_blank" href="/books/matlab-performance">additional information</a>).</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/savezip-utility">savezip utility</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/screencapture-utility" rel="bookmark" title="ScreenCapture utility">ScreenCapture utility </a> <small>The ScreenCapture utility uses purely-documented Matlab for capturing a screen region as an image from within Matlab. ...</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/improving-save-performance" rel="bookmark" title="Improving save performance">Improving save performance </a> <small>There are many different ways of improving Matlab's standard save function performance. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events" rel="bookmark" title="Matlab callbacks for Java events">Matlab callbacks for Java events </a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/savezip-utility/feed</wfw:commentRss>
			<slash:comments>22</slash:comments>
		
		
			</item>
		<item>
		<title>Ideas for a new book</title>
		<link>https://undocumentedmatlab.com/articles/ideas-for-a-new-book?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ideas-for-a-new-book</link>
					<comments>https://undocumentedmatlab.com/articles/ideas-for-a-new-book#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 22 Dec 2011 00:14:07 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Book]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2632</guid>

					<description><![CDATA[<p>With my Matlab-Java book being published, reader feedback is requested about the next book project. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/ideas-for-a-new-book">Ideas for a new book</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/new-book-accelerating-matlab-performance" rel="bookmark" title="New book: Accelerating MATLAB Performance">New book: Accelerating MATLAB Performance </a> <small>Accelerating MATLAB Performance (ISBN 9781482211290) is a book dedicated to improving Matlab performance (speed). ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-java-book" rel="bookmark" title="New book: Undocumented Secrets of MATLAB-Java Programming">New book: Undocumented Secrets of MATLAB-Java Programming </a> <small>Undocumented Secrets of Matlab-Java Programming (ISBN 9781439869031) is a book dedicated to the integration of Matlab and Java. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/blinkdagger-the-end" rel="bookmark" title="BlinkDagger &#8211; the end?">BlinkDagger &#8211; the end? </a> <small>In his latest post on BlinkDagger, Quan Quach announced that the BlinkDagger blog will be frozen following co-author Daniel Sutoyo&#8217;s hiring by The MathWorks and the continuous strain of maintaining the blog single-handedly. This is sad news indeed for the...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/2011-perspective" rel="bookmark" title="2011 perspective &amp; plans for 2012">2011 perspective &amp; plans for 2012 </a> <small>2011 has seen a continued steady growth in readership of this website. This post takes an overview of past achievements and future plans. ...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>The experience of writing my <a target="_blank" href="/matlab-java-book/">Matlab-Java book</a> was truly exhilarating. The book is now officially published and several hundred copies have been shipped already, first in America and starting last week also in the rest of the world. I hope these will all arrive before Christmas &#8211; if not then please be patient a few more days, since the initial demand has apparently exceeded the printing expectations.<br />
If you are one of those who have received the book, please be kind enough to write a review of it, in book sites such as <a target="_blank" rel="nofollow" href="http://www.amazon.com/Undocumented-Secrets-MATLAB-Java-Programming-Altman/dp/1439869030">Amazon</a> or <a target="_blank" rel="nofollow" href="http://www.barnesandnoble.com/w/undocumented-secrets-of-matlab-java-programming-yair-m-altman/1103587307?ean=9781439869031">Barnes &#038; Noble</a>.<br />
As promised, I will maintain the book&#8217;s <a target="_blank" href="/matlab-java-book/">webpage</a> with an errata list and possibly more information, as they become available.</p>
<h3 id="Question">The question of a new book</h3>
<p>As with any birth, the initial exhilaration completely overwhelms, letting me forget how hard it has been to write the book. So while this &#8220;high&#8221; lasts, I wanted to ask you my readers for your opinion regarding a possible future book.<br />
<b>Which of the following books by me, possibly co-authored with another writer, would you be interested to read and/or have in your library?</b></p>
<ol>
<li>Professional Matlab application development</li>
<li>Professional Matlab GUI</li>
<li>Matlab performance tuning</li>
<li>Undocumented Matlab &#8211; the non-Java parts</li>
<li>Some other subject (please specify)</li>
<li>None of the above</li>
</ol>
<p>Please choose only a single item, or prioritize your choices. It will be a book about only one of the above topics, not several topics. I&#8217;m not going to write another 700-page monster that takes 5 years to prepare&#8230;<br />
There are of course many factors going into a decision about whether or not to enter a book-writing project. It is a multi-year commitment that requires lots of effort, time, focus, and attention to detail. It affects the writer in a way that influences the entire family. In fact, my wife has already voted an emphatic &#8220;NO!&#8221; on this subject, and I&#8217;m pretty ambivalent about this issue myself.<br />
Please do let me know what you think in a short <a href="/articles/ideas-for-a-new-book/#respond">comment</a>. Happy Holidays everyone!</p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/ideas-for-a-new-book">Ideas for a new book</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/new-book-accelerating-matlab-performance" rel="bookmark" title="New book: Accelerating MATLAB Performance">New book: Accelerating MATLAB Performance </a> <small>Accelerating MATLAB Performance (ISBN 9781482211290) is a book dedicated to improving Matlab performance (speed). ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-java-book" rel="bookmark" title="New book: Undocumented Secrets of MATLAB-Java Programming">New book: Undocumented Secrets of MATLAB-Java Programming </a> <small>Undocumented Secrets of Matlab-Java Programming (ISBN 9781439869031) is a book dedicated to the integration of Matlab and Java. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/blinkdagger-the-end" rel="bookmark" title="BlinkDagger &#8211; the end?">BlinkDagger &#8211; the end? </a> <small>In his latest post on BlinkDagger, Quan Quach announced that the BlinkDagger blog will be frozen following co-author Daniel Sutoyo&#8217;s hiring by The MathWorks and the continuous strain of maintaining the blog single-handedly. This is sad news indeed for the...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/2011-perspective" rel="bookmark" title="2011 perspective &amp; plans for 2012">2011 perspective &amp; plans for 2012 </a> <small>2011 has seen a continued steady growth in readership of this website. This post takes an overview of past achievements and future plans. ...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/ideas-for-a-new-book/feed</wfw:commentRss>
			<slash:comments>18</slash:comments>
		
		
			</item>
		<item>
		<title>New book: Undocumented Secrets of MATLAB-Java Programming</title>
		<link>https://undocumentedmatlab.com/articles/matlab-java-book?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlab-java-book</link>
					<comments>https://undocumentedmatlab.com/articles/matlab-java-book#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 17 Nov 2011 16:14:15 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Medium risk of breaking in future versions]]></category>
		<category><![CDATA[Undocumented feature]]></category>
		<category><![CDATA[Undocumented function]]></category>
		<category><![CDATA[Book]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2577</guid>

					<description><![CDATA[<p>Undocumented Secrets of Matlab-Java Programming (ISBN 9781439869031) is a book dedicated to the integration of Matlab and Java. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-java-book">New book: Undocumented Secrets of MATLAB-Java Programming</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/types-of-undocumented-matlab-aspects" rel="bookmark" title="Types of undocumented Matlab aspects">Types of undocumented Matlab aspects </a> <small>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/new-book-accelerating-matlab-performance" rel="bookmark" title="New book: Accelerating MATLAB Performance">New book: Accelerating MATLAB Performance </a> <small>Accelerating MATLAB Performance (ISBN 9781482211290) is a book dedicated to improving Matlab performance (speed). ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-java-collections-in-matlab" rel="bookmark" title="Using Java Collections in Matlab">Using Java Collections in Matlab </a> <small>Java includes a wide selection of data structures that can easily be used in Matlab programs - this article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events" rel="bookmark" title="Matlab callbacks for Java events">Matlab callbacks for Java events </a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p><span class="alignright"><a target="_blank" rel="nofollow" href="http://www.crcpress.com/product/isbn/9781439869031#post-img"><img loading="lazy" decoding="async" title="Undocumented Secrets of Matlab-Java Programming book" src="https://undocumentedmatlab.com/book/Undocumented%20Matlab-Java/book-front-cover-CRC-3D-320x453.jpg" alt="Undocumented Secrets of Matlab-Java Programming book" width="320" height="453"/></a><!-- http://www.crcpress.com/ecommerce_product/product_detail.jsf?isbn=9781439869031 --><br />
<a target="_blank" rel="nofollow" href="http://www.crcpress.com/product/isbn/9781439869031#post-banner"><img loading="lazy" decoding="async" title="CRC discount promo code" alt="CRC discount promo code" src="https://undocumentedmatlab.com/images/CRChoriz260x69_MZK07_25perc.gif" class="aligncenter" style="margin: 20px 0pt 0pt 30px;" width="260" height="69"/></a><br />
</span> <center>Quick links: &nbsp;&nbsp;&nbsp; <a href="/matlab-java-book/#TOC">Table of Contents</a> &nbsp;&nbsp;&nbsp; <a href="/matlab-java-book/#Organization">Book organization</a> &nbsp;&nbsp;&nbsp; <a href="/matlab-java-book/#FAQ">FAQ</a> &nbsp;&nbsp;&nbsp; <a href="/matlab-java-book/#Author">About the author</a> &nbsp;&nbsp;&nbsp; <a href="/matlab-java-book/#Errata">Errata list</a></center><br />
I am extremely pleased to announce that after five years of research and hard work, my book on <b>Undocumented Secrets of Matlab-Java Programming</b> is finally published.<br />
For a variety of reasons, the Matlab-Java interface was never fully documented. This is really quite unfortunate: Java is one of the most widely used programming languages, having many times the number of programmers and programming resources as Matlab. Also unfortunate is the popular claim that while Matlab is a fine programming platform for prototyping, it is not suitable for real-world, modern-looking applications.<br />
<i><b>Undocumented Secrets of Matlab-Java Programming</b></i> (<a target="_blank" rel="nofollow" href="http://www.crcpress.com/product/isbn/9781439869031#post-isbn">CRC Press, ISBN 9781439869031</a>) aims to correct this.<br />
This book shows how using Java can significantly improve Matlab program appearance and functionality. This can be done easily and even <i>without any prior Java knowledge</i>.<br />
Readers are led step-by-step from simple to complex customizations. Within the book&#8217;s 700 pages, thousands of code snippets, hundreds of screenshots and ~1500 online references are provided to enable the utilization of this book as both a sequential tutorial and as a random-access reference suited for immediate use.<br />
This book demonstrates how:</p>
<ul>
<li>The Matlab programming environment relies on Java for numerous tasks, including networking, data-processing algorithms and graphical user-interface (GUI)</li>
<li>We can use Matlab for easy access to external Java functionality, either third-party or user-created</li>
<li>Using Java, we can extensively customize the Matlab environment and application GUI, enabling the creation of visually appealing and usable applications</li>
</ul>
<p><b>No prior Java knowledge is required</b>. All code snippets and examples are self-contained and can generally be used as-is. Advanced Java concepts are sometimes used, but understanding them is not required to run the code. Java-savvy readers will find it easy to tailor code samples for their particular needs; for Java newcomers, an introduction to Java and numerous online references are provided.<br />
<a href="/matlab-java-book/">More info about the book</a>, including detailed Table-of-Contents, book structure and FAQ, can be found on <a href="/matlab-java-book/">the book&#8217;s webpage</a>.<br />
<center><span style="background-color:#E7E7E7;"><b><a target="_blank" rel="nofollow" href="http://www.crcpress.com/product/isbn/9781439869031#post-cta">Get your book copy now</a>!</b><br />
Use promo code  <span style="background-color: rgb(255, 255, 0);"><b>MZK07</b></span> for a 25% discount and free worldwide shipping.</span></center></p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/matlab-java-book">New book: Undocumented Secrets of MATLAB-Java Programming</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/types-of-undocumented-matlab-aspects" rel="bookmark" title="Types of undocumented Matlab aspects">Types of undocumented Matlab aspects </a> <small>This article lists the different types of undocumented/unsupported/hidden aspects in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/new-book-accelerating-matlab-performance" rel="bookmark" title="New book: Accelerating MATLAB Performance">New book: Accelerating MATLAB Performance </a> <small>Accelerating MATLAB Performance (ISBN 9781482211290) is a book dedicated to improving Matlab performance (speed). ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/using-java-collections-in-matlab" rel="bookmark" title="Using Java Collections in Matlab">Using Java Collections in Matlab </a> <small>Java includes a wide selection of data structures that can easily be used in Matlab programs - this article explains how. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-java-events" rel="bookmark" title="Matlab callbacks for Java events">Matlab callbacks for Java events </a> <small>Events raised in Java code can be caught and handled in Matlab callback functions - this article explains how...</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/matlab-java-book/feed</wfw:commentRss>
			<slash:comments>14</slash:comments>
		
		
			</item>
	</channel>
</rss>
