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!