I have a .txt file that has been generated from SQL-2005 (in ANSI format). I have tried textscan
and fscanf
. The entire txt file has only numeric
data.
Online resources suggest that fscanf is FASTER than textscan but I found it otherwise.
- Textscan was much faster than fscanf
I want to try this with fread
as well but I do not know how to import data using fread. Can you please suggest/comment? Thanks.
fName = 'Test.txt' % From SQL in ANSI format, 5million rows, 5 Cols
Numofrows = 1000000 ; %1million
Numcols = 5 ;
fid = fopen(fName, 'r');
C = textscan(fid, '%f %f %f %f %f', Numofrows ) ;
C = cell2mat(C);
fclose(fid); fid = fopen(fName, 'r');
[C, Count] = fscanf(fid, '%f %f %f %f %f', Numofrows * Numcols ) ;
C = reshape(C, Count./Numofrows , Numofrows ) ; C=C';