0

我有大格式的文本文件(200 Mb),其中包含易于阅读和保存的数据。格式的周期性约为 72 行,我想要一个包含 72 行模板格式的其他文件。有没有办法做到这一点?

理想的方式是

formatstring = fileread(templatefile)

fileToRead = fopen(LargeFile,'r')

while ~feof(fileToRead)

object{i} = textscan(fileToRead,formatstring)

i = i+1
end

模板文件如下所示:

CASE # %16f            DATE: %s

AILERON ANGLE        STAB ANGLE
%4.2f                 %4.2f

ALPHA      BETA     GAMMA

%4.2f      %4.2f      %4.2f
4

1 回答 1

0

If you want to read a format file and transform that into a valid format string, use this:

% read format file
fid = fopen('untitled.txt', 'r');
A = textscan(fid, '%s');
fclose(fid);

% transform into proper format string
A = A{1}(~cellfun('isempty', regexp(A{1}, '%')))
A = [A{:}];

in that case,

>> A
A = 
    %16f%s%4.2f%4.2f%4.2f%4.2f%4.2f

which you can use directly in the textscan in your while-loop.

于 2012-11-05T07:23:59.217 回答