0

数字と多数のテキスト行の両方を含むテキスト ファイルがあります。しかし、Matlab で数値を 2 つの別々の行列として読み取る必要があります。ファイルは次のようになります。

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

1 に答える 1

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"
于 2013-06-24T12:55:13.583 に答える