Creating adjacency matrix for network analysis
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Vishnu Kant
le 22 Août 2018
Modifié(e) : Vishal Bhutani
le 29 Août 2018
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?
0 commentaires
Réponse acceptée
Vishal Bhutani
le 29 Août 2018
Modifié(e) : Vishal Bhutani
le 29 Août 2018
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 commentaires
Vishal Bhutani
le 29 Août 2018
Modifié(e) : Vishal Bhutani
le 29 Août 2018
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.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!