0

我有一个 raw.txt 文件,如下所示:

#   Angle   Data A       DATA B     ...       
1   45    1440.352365   3.619902121
2   45    1440.352365   3.619902121
3   45    1440.192496   3.632952692
1   45    1440.192496   3.632952692
2   45    1440.192496   3.632952692
3   45    1440.192496   3.632952692
4   45    1440.192496   3.632952692
.
.
.

第一行(#)在 3 之后重复。它应该转到 4、5、6... 我想编写一个脚本,只更改该行,其余部分保持原样。我正在写这样的东西,但出现错误,我无法弄清楚我们的

   function TrailRestFix(filename)

infile = fopen(filename, 'r');
outfile = fopen(filename, 'w');
i = 0;
while ~feof(infile)
    line = fgets(infile);
    space_idx = strfind(line, ' ');
    if i == 0
        fprintf(outfile,'%s',line);
    else
        fprintf(outfile,'%i %s',i,line(space_idx(1)+1:end));
    end
    i = i + 1;
end
fclose(infile);
fclose(outfile);

end
4

0 回答 0