Clear Filters
Clear Filters

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 views (last 30 days)
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 Comments
Mouli Sarkar
Mouli Sarkar on 13 Apr 2021
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?

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!