I want to read a .txt file. I want to read each of the row from the .txt file except the first element of each row. each of the .txt file need to be converted to a matrix. Please some one suggest how to do it.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
intput file:
1,0,-1,-1,0,0,-1,0,0,0
2,0,-1,-1,0,0,0,0,0,0
3,0,-1,-1,0,0,0,0,1,0
4,0,-1,0,0,0,-1,-1,0,0
5,0,-1,0,0,0,-1,0,0,0
6,0,-1,0,0,0,-1,1,0,0
7,0,-1,0,0,0,0,-1,1,0
8,0,-1,0,0,0,0,0,-1,0
9,0,-1,0,0,0,0,0,1,0
10,0,-1,0,0,0,0,1,-1,0
11,0,-1,0,0,0,0,1,0,0
12,0,-1,0,0,0,0,1,1,0
13,0,-1,0,0,0,1,0,0,0
14,0,-1,0,0,0,1,1,0,0
15,0,-1,1,0,0,0,0,0,0
16,0,-1,1,0,0,0,0,1,0
17,0,-1,1,0,0,1,0,0,0
18,0,0,0,0,0,0,1,1,0
19,0,0,0,0,0,1,1,0,0
20,0,0,0,1,0,0,1,0,0
21,0,0,0,1,0,0,1,1,0
22,0,0,1,1,0,0,0,1,0
Attempted code:
fileID=fopen('topo.txt','r');
formatSpec='%c';
A=fscanf(fileID,formatSpec);
disp(A);
[m, n] = size(A);
for i = 1:m
vec{i} = A(i, :);
B{i}=reshape(vec{i},3,3);
disp("rows");
disp(vec{i});
disp("matrix");
disp(B{i});
end;
9 Kommentare
Rik
am 13 Apr. 2021
Please do not post a question in two places. You can post a link to the other thread instead.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Standard File Formats finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!