Thread Subject: matrix transpose - File I/O question

Subject: matrix transpose - File I/O question

From: "G.A.M.

Date: 16 Sep, 2007 03:08:32

Message: 1 of 1

% 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.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
export G.A.M. 16 Sep, 2007 09:51:38
import G.A.M. 16 Sep, 2007 09:51:38
ascii G.A.M. 16 Sep, 2007 09:51:38
fprintf G.A.M. 16 Sep, 2007 09:51:37
fileio G.A.M. 16 Sep, 2007 09:51:37
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com