<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156218</link>
    <title>MATLAB Central Newsreader - matrix transpose - File I/O question</title>
    <description>Feed for thread: matrix transpose - File I/O question</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>Sun, 16 Sep 2007 03:08:32 -0400</pubDate>
      <title>matrix transpose - File I/O question</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/156218#392481</link>
      <author> &quot;G.A.M.</author>
      <description>% Steve Amphlett wrote:&lt;br&gt;
% &amp;gt; Matthew Crema wrote:&lt;br&gt;
%&lt;br&gt;
% &amp;gt; &amp;lt;snip, line-by-line reading is slow c.f. ML's &amp;lt;load&amp;gt; ...&lt;br&gt;
%&lt;br&gt;
% &amp;gt;&amp;gt;What is the load command doing that I am not?&lt;br&gt;
%&lt;br&gt;
% &amp;gt; I think it's probably down to buffering. If you read a file&lt;br&gt;
% &amp;gt; line-by-line using C's fgets() function in a loop, the performance&lt;br&gt;
is&lt;br&gt;
% &amp;gt; much better than doing the equivalent in ML.&lt;br&gt;
%&lt;br&gt;
% &amp;gt; Based on postings to this NG (and my limited experience of using&lt;br&gt;
ML's&lt;br&gt;
% &amp;gt; file reading functions), a bulk read of the whole file, followed&lt;br&gt;
by&lt;br&gt;
% &amp;gt; string parsing of the resulting character array is a good&lt;br&gt;
approach.&lt;br&gt;
% &amp;gt; A MEX file is better, and normally quicker than &amp;lt;load&amp;gt; too.&lt;br&gt;
%&lt;br&gt;
% Thanks Steve!&lt;br&gt;
%&lt;br&gt;
% tic&lt;br&gt;
% fid = fopen('mydata.dat','r');&lt;br&gt;
% header = fgetl(fid); % Chop off the header&lt;br&gt;
% data = fscanf(fid,'%f',[4,inf]); % 4x72000 matrix&lt;br&gt;
% data=data'; % Not sure why I have to do this&lt;br&gt;
% fclose(fid)&lt;br&gt;
% toc&lt;br&gt;
%&lt;br&gt;
% 2.92 seconds! (Compare to load which takes 3.795 seconds)&lt;br&gt;
%&lt;br&gt;
% -Matt&lt;br&gt;
&lt;br&gt;
from above:&lt;br&gt;
% data=data'; % Not sure why I have to do this&lt;br&gt;
&lt;br&gt;
from another post:&lt;br&gt;
c=c.';&lt;br&gt;
txt=sprintf([repmat('%s\t',1,size(c,1)),'\n'],c{:});&lt;br&gt;
&lt;br&gt;
I like the results of this second example, but I never would have&lt;br&gt;
thought to write that on my own.&lt;br&gt;
&lt;br&gt;
I generally feel that many of the file and string functions (textscan,&lt;br&gt;
etc.) transpose my string data in unexpected ways. I would appreciate&lt;br&gt;
it if anyone would kindly explain the general rule so I can figure out&lt;br&gt;
how to write the proper code without guessing. Thanks.</description>
    </item>
  </channel>
</rss>

