【发布时间】:2016-08-10 06:46:47
【问题描述】:
我有一个关于 octave 或 matlab 数据后处理的问题。 我有从 fluent 导出的文件,如下所示:
"Surface Integral Report"
Mass-Weighted Average
Static Temperature (k)
crossplane-x-0.001 1242.9402
crossplane-x-0.025 1243.0017
crossplane-x-0.050 1243.2036
crossplane-x-0.075 1243.5321
crossplane-x-0.100 1243.9176
我想使用 octave/matlab 进行后期处理。 如果我逐行读取第一行,并且只将带有“crossplane-x-”的行保存到一个新文件中,或者直接将这些行中的数据保存到一个矩阵中。因为我有很多类似的文件,我可以通过调用它们的标题来制作图。 但是我在识别包含字符“crossplane-x-”的行时遇到了麻烦。我正在尝试做这样的事情:
clear, clean, clc;
% open a file and read line by line
fid = fopen ("h20H22_alongHGpath_temp.dat");
% save full lines into a new file if only chars inside
txtread = fgetl (fid)
num_of_lines = fskipl(fid, Inf);
char = 'crossplane-x-'
for i=1:num_of_lines,
if char in fgetl(fid)
[x, nx] = fscanf(fid);
print x
endif
endfor
fclose (fid);
有人能解释一下这个问题吗?我使用了正确的功能吗?谢谢。
【问题讨论】:
-
我认为 grep 或 awk 更适合这个任务
-
谢谢安迪,我用过 sed ...
标签: octave