Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!g4g2000hsf.googlegroups.com!not-for-mail
From:  "G.A.M." <x0Zero@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: matrix transpose - File I/O question
Date: Sun, 16 Sep 2007 03:08:32 -0000
Organization: http://groups.google.com
Lines: 49
Message-ID: <1189912112.365626.73130@g4g2000hsf.googlegroups.com>
NNTP-Posting-Host: 24.129.101.179
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1189912112 27268 127.0.0.1 (16 Sep 2007 03:08:32 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 16 Sep 2007 03:08:32 +0000 (UTC)
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: g4g2000hsf.googlegroups.com; posting-host=24.129.101.179;
Xref: news.mathworks.com comp.soft-sys.matlab:428701



% Steve Amphlett wrote:
% > Matthew Crema wrote:
%
% > <snip, line-by-line reading is slow c.f. ML's <load> ...
%
% >>What is the load command doing that I am not?
%
% > I think it's probably down to buffering. If you read a file
% > line-by-line using C's fgets() function in a loop, the performance
is
% > much better than doing the equivalent in ML.
%
% > Based on postings to this NG (and my limited experience of using
ML's
% > file reading functions), a bulk read of the whole file, followed
by
% > string parsing of the resulting character array is a good
approach.
% > A MEX file is better, and normally quicker than <load> too.
%
% Thanks Steve!
%
% tic
% fid = fopen('mydata.dat','r');
% header = fgetl(fid); % Chop off the header
% data = fscanf(fid,'%f',[4,inf]); % 4x72000 matrix
% data=data'; % Not sure why I have to do this
% fclose(fid)
% toc
%
% 2.92 seconds! (Compare to load which takes 3.795 seconds)
%
% -Matt

from above:
% data=data'; % Not sure why I have to do this

from another post:
c=c.';
txt=sprintf([repmat('%s\t',1,size(c,1)),'\n'],c{:});

I like the results of this second example, but I never would have
thought to write that on my own.

I generally feel that many of the file and string functions (textscan,
etc.) transpose my string data in unexpected ways. I would appreciate
it if anyone would kindly explain the general rule so I can figure out
how to write the proper code without guessing. Thanks.