我有 .txt 格式的非常大的数据文件(通常为 30Gb 到 60Gb)。我想找到一种方法来自动抽取文件而不先将它们导入内存。我的 .txt 文件包含两列数据,这是一个示例文件: https ://www.dropbox.com/s/87s7qug8aaipj31/RTL5_57.txt
到目前为止,我所做的是将数据导入变量“C”,然后对数据进行下采样。这种方法的问题是变量“C”经常在程序更改为抽取之前填充 MATLAB 的内存容量:
function [] = textscan_EPS(N,D,fileEPS )
%fileEPS: .txt address
%N: number of lines to read
%D: Decimation factor
fid = fopen(fileEPS);
format = '%f\t%f';
C = textscan(fid, format, N, 'CollectOutput', true);% this variable exceeds memory capacity
d = downsample(C{1},D);
plot(d);
fclose(fid);
end
我该如何修改这一行:
C = textscan(fid, format, N, 'CollectOutput', true);
因此,它通过将 .txt 文件的每隔一行或每 3 行等从磁盘导入到内存中的变量“C”,从而有效地抽取数据。
任何帮助将非常感激。
干杯,吉姆
PS我一直在玩的另一种方法使用“fread”,但它遇到了同样的问题:
function [d] = fread_EPS(N,D,fileEPS)
%N: number of lines to read
%D: decimation factor
%fileEPS: location of .txt fiel
%read in the data as characters
fid = fopen(fileEPS);
c = fread(fid,N*19,'*char');% EWach line of .txt has 19 characters
%Parse and read the data into floading point numbers
f=sscanf(c,'%f');
%Reshape the data into a two column format
format long
d=decimate((flipud(rot90(reshape(f,2,[])))),D); %reshape for 2 colum format, rotate 90, flip veritically,decimation factor