Creating adjacency matrix for network analysis

조회 수: 1 (최근 30일)
Vishnu Kant
Vishnu Kant 2018년 8월 22일
편집: Vishal Bhutani 2018년 8월 29일
I have a matrix 29*33 like in the table(attached)/picture
. The first column represent number of individual and each row represent who is he/she friend with like for individual 1 he is friend with 2,3,5,6 and so on! In the matrix I have deleted the individual whose data was missing so If you see first column I have deleted row 4,13,14 and 23. Also since they were missing I set the value of 4,13 ,14 and 23 as 0 wherever they were mentioned as a friend by the remaining individuals so if you see friend's of 1(1st row) you see that he is friend with 2, 3 also 4 but its 0 for 4 since it was missing in the 1st column and then 5 and so on!How should i go about coding in matlab to get an adjacency matrix of this given matrix?

채택된 답변

Vishal Bhutani
Vishal Bhutani 2018년 8월 29일
편집: Vishal Bhutani 2018년 8월 29일
Based on my understanding, you want to create an adjacency matrix from test.mat and there is some discrepancy in the data. As you may aware, adjacency matrix is a symmetric matrix, hence one of the simple suggestion would be to remove those columns which has discrepancy ( like 4, 13, 14, and 23 ). Then the matrix obtain is symmetric and then you can get the adjacency matrix by having values assign to 1 which are friends and 0 to those who are not. Sample code which you can try:
x = [1:3,5:12,15:22,24:33]; %removing 4,13,14,23 from test
test1 = test(:,x);
adj_matr = test1>0; %assign value 1 to friends and 0 for no friends
Another thing which you can try that putting the columns (4, 13, 14, and 23) in rows which will make the matrix symmetric and then you can obtain adjacency matrix.
  댓글 수: 2
Vishnu Kant
Vishnu Kant 2018년 8월 29일
Not exactly,column 4,13,14 and 23 does not necessarily has information for individual 4,13,14,23 for example for column 4, row 2 and 3 has 5 and 11 respectively. So if i remove column 4 I loose information 5 and 11. I will try to reframe my question with the following example:
I have a 4x6 matrix (directed network) similar to the following example:So first column represent individuals and each rows represent individual friendship with other individuals so first row represent individual 1 friendship with 2 and 5 and similarly row 3 represent individual 5 friendship with individuals 2 and 6. Zeros have no meaning.
[
1 2 0 5 0 0;
2 1 0 0 5 6;
5 2 6 0 0 0;
6 1 2 0 0 5; ]
So now since there are four individuals I want *4x4 adjacency matrix representing friendship meaning 0 indicating no friendship and 1 indicating friendship*. So first row in the following represent individual 1 friendship with 2,5 as 1 meaning they are friend and 0 for 6 they are not friend. Similarly row two represent friendship individual 2 with 1,5 and 6 as 1 meaning he/she is friend with all the individuals.
[ 0 1 1 0;
1 0 1 1;
0 1 0 1;
1 1 1 0; ]
Vishal Bhutani
Vishal Bhutani 2018년 8월 29일
편집: Vishal Bhutani 2018년 8월 29일
I understood your question, Earlier I was thinking that each column correspond to an individual and it is a uni-directed network. So you can try one thing that create a matrix adj_matr of zeros size 29x33. Then for each row starting from second column search for the numbers from 1 to 33 in test matrix and if you find the numbers in columns insert one in matrix adj_matr there. After that remove column 4,13,14 and 23 as they are not present in the test matrix and they will have a zero value. So you got your adjacency matrix adj_matr of size 29x29. Hoping that this will resolve your issue.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Networks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by