我有关于大文本文件输入(~500k行)和后续数据解析的以下性能问题.
考虑data.txt具有以下示例性结构的文本文件,其具有两个标题行可以在文本文件中的某处重新出现的特性:
Name Date Val1 val2
--- ------- ---- ----
BA 2013-09-07 123.123 1232.22
BA 2013-09-08 435.65756 2314.34
BA 2013-09-09 234.2342 21342.342
Run Code Online (Sandbox Code Playgroud)
我编写的代码和以下代码如下:
%# Read in file using textscan, read all values as string
inFile = fopen('data.txt','r');
DATA = textscan(inFile, '%s %s %s %s');
fclose(inFile);
%# Remove the header lines everywhere in DATA:
%# Search indices of the first entry in first cell, i.e. 'Name', and remove
%# all lines corresponding to …Run Code Online (Sandbox Code Playgroud)