File io Matlab中的文本阅读

File io Matlab中的文本阅读,file-io,matlab-guide,File Io,Matlab Guide,我有一个文本文件,其中包括数字和大量的文本行。但我只需要在Matlab中将数字作为两个独立的矩阵来读取。文件如下所示: finite element method Node Number 1 2 3 1 3 4 2 3 4 coordinates: 10 20 0 20 20 20 14 0 你能再清楚一点文件格式吗?行“节点编号”和“坐标:”是文件的一部分,还是有两个单独的文件?包含数字的行之间有空行吗?嗨,首先,谢谢你的关注。它们都在同一个文件中,数字之间没有空行。事实上,我的问题不知

我有一个文本文件,其中包括数字和大量的文本行。但我只需要在Matlab中将数字作为两个独立的矩阵来读取。文件如下所示:

finite element method 
Node Number
1 2 3
1 3 4
2 3 4
coordinates:
10 20
0 20
20 20
14 0


你能再清楚一点文件格式吗?行“节点编号”和“坐标:”是文件的一部分,还是有两个单独的文件?包含数字的行之间有空行吗?嗨,首先,谢谢你的关注。它们都在同一个文件中,数字之间没有空行。事实上,我的问题不知怎么解决了。我写的代码是这样的。你有更好的主意吗???
fid=fopen('filename.txt'); %opening the file
while ~feof(fid) %reading up to end of the file

tline = fgetl(fid); %reading line by line
if   strcmp(tline, 'Node Number') %finding the line containing " Node Number"
    break    %stop reading if the "Node Number" was detected
end
end

Nnum =transpose( fscanf(fid,'%d ' , [3 Inf])) %reading the lines after the line which we were stop
                                          % reading would stop as soon
                                          % as the format of reading
                                          % doesn't match anymore


while ~feof(fid) %continuing reading line by line again

tline = fgetl(fid);
if   strcmp(tline, 'coordinates:')%stop when the line "coordinates" 
                                  was detected
    break    
end
end

Coordinate =transpose( fscanf(fid,'%d ' , [2 Inf])) %reading lines after line
                                                "coordinate"