I've found the fastest way to read BIG csv files into Matlab is to memory-map them and parse the contents as a single string. Try playing with this example code:
fname = 'file.csv';
fstats = dir(fname);
% Map the file as one long character string
m = memmapfile(fname, 'Format', {'uint8' [ 1 fstats.bytes] 'asUint8'});
textdata = char(m.Data(1).asUint8);
% Find the end of each line, and use the line ends to form an index array
row = strfind(textdata, sprintf('
'));
row = [[1; row(1:end-1)'+2] row' - 1];
% Fix-up if there is no
at the end of the last line
if (row(end) < fstats.bytes - 2)
row = [row; [row(end) + 2, fstats.bytes]];
end
numrows = size(row, 1);
% Create output variables
Time = zeros(numrows, 1);
Value = zeros(numrows, 1);
% Parse each line of the data (I'm ignoring the first line for simplicity)
for RowNum = 2:numrows
data = textscan(textdata(row(RowNum,1):row(RowNum,2)), '%[^,]%f', 'delimiter', ',');
Time(RowNum) = datenum(data{:});
Value(RowNum) = data{2};
end
% Remove the file mapping
clear('m');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…