<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172960</link>
    <title>MATLAB Central Newsreader - Writing Binary file to reduce file size</title>
    <description>Feed for thread: Writing Binary file to reduce file size</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 21 Jul 2008 16:42:03 -0400</pubDate>
      <title>Writing Binary file to reduce file size</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172960#444354</link>
      <author>Pete sherer</author>
      <description>Hi,&lt;br&gt;
Are there any example how to use Matlab to make the binary&lt;br&gt;
file of data. The goal is to reduce the file size as well as&lt;br&gt;
the accessing time to the file. Most of the data contain&lt;br&gt;
zero, so I hope binary file can be much smaller than the&lt;br&gt;
ascii file.&lt;br&gt;
&lt;br&gt;
Thanks a lot,</description>
    </item>
    <item>
      <pubDate>Mon, 21 Jul 2008 16:56:25 -0400</pubDate>
      <title>Re: Writing Binary file to reduce file size</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172960#444359</link>
      <author>Peter Boettcher</author>
      <description>&quot;Pete sherer&quot; &amp;lt;tsh@abg.com&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; Are there any example how to use Matlab to make the binary&lt;br&gt;
&amp;gt; file of data. The goal is to reduce the file size as well as&lt;br&gt;
&amp;gt; the accessing time to the file. Most of the data contain&lt;br&gt;
&amp;gt; zero, so I hope binary file can be much smaller than the&lt;br&gt;
&amp;gt; ascii file.&lt;br&gt;
&lt;br&gt;
Yes indeed.&lt;br&gt;
&lt;br&gt;
If you intend to load the data back into MATLAB, and only MATLAB, just&lt;br&gt;
use &quot;save&quot; and &quot;load&quot;.  The resulting file is &quot;binary&quot;, though not in a&lt;br&gt;
simple format.&lt;br&gt;
&lt;br&gt;
If you wish to access the data from another programming language, see&lt;br&gt;
the documentation for fopen, fwrite, fread, and fclose.&lt;br&gt;
&lt;br&gt;
-Peter</description>
    </item>
    <item>
      <pubDate>Thu, 24 Jul 2008 04:47:01 -0400</pubDate>
      <title>Re: Writing Binary file to reduce file size</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172960#445053</link>
      <author>Bill McKeeman</author>
      <description>Peter Boettcher &amp;lt;boettcher@ll.mit.edu&amp;gt; wrote in message &lt;br&gt;
&amp;lt;muy4p6j89c6.fsf@G99-Boettcher.llan.ll.mit.edu&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Pete sherer&quot; &amp;lt;tsh@abg.com&amp;gt; writes:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt; Are there any example how to use Matlab to make the &lt;br&gt;
binary&lt;br&gt;
&amp;gt; &amp;gt; file of data. The goal is to reduce the file size as &lt;br&gt;
well as&lt;br&gt;
&amp;gt; &amp;gt; the accessing time to the file. Most of the data contain&lt;br&gt;
&amp;gt; &amp;gt; zero, so I hope binary file can be much smaller than the&lt;br&gt;
&amp;gt; &amp;gt; ascii file.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Yes indeed.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you intend to load the data back into MATLAB, and only &lt;br&gt;
MATLAB, just&lt;br&gt;
&amp;gt; use &quot;save&quot; and &quot;load&quot;.  The resulting file is &quot;binary&quot;, &lt;br&gt;
though not in a&lt;br&gt;
&amp;gt; simple format.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you wish to access the data from another programming &lt;br&gt;
language, see&lt;br&gt;
&amp;gt; the documentation for fopen, fwrite, fread, and fclose.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -Peter&lt;br&gt;
&lt;br&gt;
I suggest you try&lt;br&gt;
&lt;br&gt;
&amp;gt;&amp;gt; help zip&lt;br&gt;
&lt;br&gt;
/s/ Bill</description>
    </item>
    <item>
      <pubDate>Thu, 24 Jul 2008 05:09:01 -0400</pubDate>
      <title>Re: Writing Binary file to reduce file size</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172960#445056</link>
      <author>Pete sherer</author>
      <description>I think what I want to do is to write a binary file such&lt;br&gt;
that I can use other programs besides matlab to read the file.  &lt;br&gt;
I just need an example how to write and read it, at least&lt;br&gt;
from Matlab workspace.  Finally I will use other&lt;br&gt;
applications to read the data file.  &lt;br&gt;
I think this is a common example, but I can't seem to find&lt;br&gt;
the solution.&lt;br&gt;
Thanks for all the advice in advance.</description>
    </item>
    <item>
      <pubDate>Thu, 24 Jul 2008 06:33:31 -0400</pubDate>
      <title>Re: Writing Binary file to reduce file size</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172960#445068</link>
      <author>NZTideMan</author>
      <description>On Jul 24, 5:09=A0pm, &quot;Pete sherer&quot; &amp;lt;t...@abg.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; I think what I want to do is to write a binary file such&lt;br&gt;
&amp;gt; that I can use other programs besides matlab to read the file. =A0&lt;br&gt;
&amp;gt; I just need an example how to write and read it, at least&lt;br&gt;
&amp;gt; from Matlab workspace. =A0Finally I will use other&lt;br&gt;
&amp;gt; applications to read the data file. =A0&lt;br&gt;
&amp;gt; I think this is a common example, but I can't seem to find&lt;br&gt;
&amp;gt; the solution.&lt;br&gt;
&amp;gt; Thanks for all the advice in advance.&lt;br&gt;
&lt;br&gt;
netCDF is the answer.&lt;br&gt;
Google it.</description>
    </item>
    <item>
      <pubDate>Thu, 24 Jul 2008 07:17:01 -0400</pubDate>
      <title>Re: Writing Binary file to reduce file size</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172960#445074</link>
      <author>Rune Allnor</author>
      <description>On 24 Jul, 07:09, &quot;Pete sherer&quot; &amp;lt;t...@abg.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; I think what I want to do is to write a binary file such&lt;br&gt;
&amp;gt; that I can use other programs besides matlab to read the file. =A0&lt;br&gt;
&amp;gt; I just need an example how to write and read it, at least&lt;br&gt;
&amp;gt; from Matlab workspace. =A0Finally I will use other&lt;br&gt;
&amp;gt; applications to read the data file. =A0&lt;br&gt;
&amp;gt; I think this is a common example, but I can't seem to find&lt;br&gt;
&amp;gt; the solution.&lt;br&gt;
&lt;br&gt;
The trick is to use FREAD and FWRITE. If you want to read data&lt;br&gt;
from a file known to contain one 100 x 200 array of doubles,&lt;br&gt;
you do something like&lt;br&gt;
&lt;br&gt;
fid =3D fopen('myfile.dat');&lt;br&gt;
A=3Dfread(fid,[100,200],'double');&lt;br&gt;
fclose(fid);&lt;br&gt;
&lt;br&gt;
and similar when you write bac to file.&lt;br&gt;
&lt;br&gt;
Just be aware of somewhat awkward issues with file formats&lt;br&gt;
(rows-first or column-first storage) and binary numerical&lt;br&gt;
formats (big-endian or little-endian formats).&lt;br&gt;
&lt;br&gt;
Rune</description>
    </item>
    <item>
      <pubDate>Thu, 24 Jul 2008 09:02:14 -0400</pubDate>
      <title>Re: Writing Binary file to reduce file size</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172960#445103</link>
      <author>NZTideMan</author>
      <description>On Jul 24, 7:17=A0pm, Rune Allnor &amp;lt;all...@tele.ntnu.no&amp;gt; wrote:&lt;br&gt;
&amp;gt; On 24 Jul, 07:09, &quot;Pete sherer&quot; &amp;lt;t...@abg.com&amp;gt; wrote:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I think what I want to do is to write a binary file such&lt;br&gt;
&amp;gt; &amp;gt; that I can use other programs besides matlab to read the file. =A0&lt;br&gt;
&amp;gt; &amp;gt; I just need an example how to write and read it, at least&lt;br&gt;
&amp;gt; &amp;gt; from Matlab workspace. =A0Finally I will use other&lt;br&gt;
&amp;gt; &amp;gt; applications to read the data file. =A0&lt;br&gt;
&amp;gt; &amp;gt; I think this is a common example, but I can't seem to find&lt;br&gt;
&amp;gt; &amp;gt; the solution.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; The trick is to use FREAD and FWRITE. If you want to read data&lt;br&gt;
&amp;gt; from a file known to contain one 100 x 200 array of doubles,&lt;br&gt;
&amp;gt; you do something like&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; fid =3D fopen('myfile.dat');&lt;br&gt;
&amp;gt; A=3Dfread(fid,[100,200],'double');&lt;br&gt;
&amp;gt; fclose(fid);&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; and similar when you write bac to file.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Just be aware of somewhat awkward issues with file formats&lt;br&gt;
&amp;gt; (rows-first or column-first storage) and binary numerical&lt;br&gt;
&amp;gt; formats (big-endian or little-endian formats).&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Rune&lt;br&gt;
&lt;br&gt;
IMHO, using fread and fwrite when you want to maybe read the data in&lt;br&gt;
using a different program is not advisable.  I've been there and done&lt;br&gt;
that and everytime, reading the binary files on a different platform&lt;br&gt;
or in a different program was a problem.&lt;br&gt;
That's why I suggested netCDF.   Files written in netCDF on a Cray for&lt;br&gt;
example can be read on a PC or Mac in Matlab, Fortran, C, or&lt;br&gt;
whatever.  It is totally portable.</description>
    </item>
    <item>
      <pubDate>Thu, 24 Jul 2008 09:44:03 -0400</pubDate>
      <title>Re: Writing Binary file to reduce file size</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172960#445114</link>
      <author>David </author>
      <description>&quot;Pete sherer&quot; &amp;lt;tsh@abg.com&amp;gt; wrote in message &amp;lt;g62e8r$i37&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; Are there any example how to use Matlab to make the &lt;br&gt;
binary&lt;br&gt;
&amp;gt; file of data. The goal is to reduce the file size as &lt;br&gt;
well as&lt;br&gt;
&amp;gt; the accessing time to the file. Most of the data contain&lt;br&gt;
&amp;gt; zero, so I hope binary file can be much smaller than the&lt;br&gt;
&amp;gt; ascii file.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks a lot,&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
and of course 'binary' isn't always smaller.  if you write &lt;br&gt;
your zero data as doubles with fwrite it takes 64 bits.  &lt;br&gt;
if you format it properly in a tab or comma delimited file &lt;br&gt;
it can be only 16 bits.  create your own binary format and &lt;br&gt;
you could reduce it even more using simple compression &lt;br&gt;
techniques, but then you would have to write the reader to &lt;br&gt;
uncompress it.</description>
    </item>
  </channel>
</rss>

