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.
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rik
2021-4-13
Please do not post a question in two places. You can post a link to the other thread instead.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!