Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to save time loading data from file
Date: Mon, 4 Aug 2008 13:20:03 +0000 (UTC)
Organization: Pierburg GmbH
Lines: 54
Message-ID: <g76vm3$pmj$1@fred.mathworks.com>
References: <g75abr$40d$1@fred.mathworks.com> <005e6e4d-a014-4c18-bfd1-3ebd502aec08@s50g2000hsb.googlegroups.com> <g75evu$eg$1@fred.mathworks.com> <g75k8l$ppg$1@fred.mathworks.com> <g75ub5$k64$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1217856003 26323 172.30.248.37 (4 Aug 2008 13:20:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 4 Aug 2008 13:20:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 872224
Xref: news.mathworks.com comp.soft-sys.matlab:483497



"ggk " <ggkmath@comcast.net> wrote in message <g75ub5$k64
$1@fred.mathworks.com>...
> Thanks Per, The fscanf routine works twice as fast as load
> ('filename'). Unfortunately I need an order of magnitude 
> improvement, at least.
> 
> [..]


some of my experience (R2008a):

% ========================

% generate a test file of ~15MB:

A = rand(1,1)+reshape(linspace(0,100,1e6),1e6/20,20); 

filename= 'C:\test.txt';

save(filename,'A','-ascii');

% >6s ---------------------

T = textread(filename);

C = importdata(filename);

L = load(filename);  
% no effect of the '-ascii' option

% ~2s ---------------------

M = dlmread(filename);

% <=1s --------------------

B = txt2mat(filename,0,20,'Infolevel',0);
% file exchange, based on fread & sscanf

tic, fid = fopen(filename);
D = textscan(fid, repmat('%f ',1,20), 'CollectOutput',true);
D = D{1};
fclose(fid); toc

% ========================


The approximate times given are measured by repeated runs, 
so there'll be some notable effect of caching the import 
function and the test files. textscan is the fasted one, I 
wonder if it beats your fscanf solution.

regards
Andres