4
    function [input]= read_input()

    fid= fopen ('input.txt');

    tline=fgets(fid);

           while ischar(tline)
                if tline =='#'

                end
             tline = fgets(fid);
    end

        fclose(fid)

到目前为止,这是我的代码,我正在尝试读取文件,然后只取数值,同时跳过以 # 开头的行。

感谢您提前提供任何帮助。

4

2 回答 2

3

我推荐一种不同的方法。

利用 MATLAB 提供的内置功能,并使用textscan

fid = fopen('input.txt');
C = textscan(fid, '%s', 'Delimiter', '\n', 'CommentStyle', '#');
C = C{:};
fclose(fid);

在此之后,您将得到一个元胞数组C,其中包含输入文件中不以井号开头的所有行。

于 2013-09-23T21:02:49.030 回答
0

更新if

if tline(1) =='#'
    continue;
end
于 2013-09-23T20:34:43.077 回答