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
Mouli Sarkar
Mouli Sarkar 2021년 4월 13일
sir I need for help.
Suppose I have a circuit like this below image
here A is activating B and B is activating C.
For this circuit Matrix be like
source node
A B C
-------------------------------------------
A | 0 0 0
Target B | 1 0 0
node C | 0 1 0
That means j th elements are controling i th elements. If A is activating B then there is 1. If A was inhibiting B there will be -1 in the matrix. And the type of the link for inhibition would be like this ---| .
In the above code upto this matrix formation is done.
I want to creat separate .topo file for seperate matrics should be store in separate folder according to there number. And the text file should be in this format I am mentioning below.
Source Target Type
A B 1
B C 1
1 signifies activation
2 signifies inactivation
how can do this part of coding?
Rik
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 CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by