Textscan vs importdata

Hi,
I though textscan was faster than importdata but it seems to me that for bigger file importdata is faster. Any explanations?
Here is the code :
tic
raw1=importdata('185mo.csv');
toc
tic
fid = fopen('185mo.csv');
raw2 = textscan(fid, '%f %f %f', 'delimiter', ',', ...
'EmptyValue', -NaN,'HeaderLines',16);
fclose(fid);
toc
Here is the result :
Elapsed time is 30.462402 seconds.
Elapsed time is 38.665811 seconds.

4 件のコメント

Oleg Komarov
Oleg Komarov 2012 年 2 月 14 日
Consider that importdata uses textscan. I would suggest to go in debug mode to check what options they use, but I suspect it's the NaN padding.
Walter Roberson
Walter Roberson 2012 年 2 月 14 日
Interesting, I did not know that -NaN had a different representation than NaN, but it seems to (in R2008b at least)
>> sprintf('%16lx\n',typecast(nan,'uint64'))
ans =
fff8000000000000
>> sprintf('%16lx\n',typecast(-nan,'uint64'))
ans =
7ff8000000000000
Benoit
Benoit 2012 年 2 月 14 日
Well I've tried without EmptyValue,
tic
raw1=importdata('185mo.csv');
toc
tic
fid = fopen('185mo.csv');
raw2 = textscan(fid, '%f %f %f', 'delimiter', ',', ...
'HeaderLines',16);
fclose(fid);
toc
Here is the result:
Elapsed time is 28.735443 seconds.
Elapsed time is 36.212666 seconds.
Jan
Jan 2012 年 7 月 9 日
編集済み: Jan 2012 年 7 月 9 日
@Walter: In R2009a NaN and -NaN are "000000f8ff" on a Win7/64 PC.

サインインしてコメントする。

回答 (1 件)

xiangsheng guan
xiangsheng guan 2012 年 7 月 9 日

0 投票

I find that importdata uses fread for .txt files. But I can access neither source file of fread nor textscan.

質問済み:

2012 年 2 月 14 日

編集済み:

2013 年 10 月 12 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by