How to calculate adjacency matrix ?

22 views (last 30 days)
muhammad ismat
muhammad ismat on 23 Mar 2018
Answered: Walter Roberson on 24 Mar 2018
if i have data rearranged as follow
0 1 2 3
1 3 5 7
2 4 6 7
where this data mean that first element of first row connect with remaining element in first row and second element of second row connect with remaining element in second row so i want to calculate the adjacency matrix in the form
0 1 1 1 0 0 0 0
0 0 0 1 0 1 0 1
0 0 0 0 4 0 1 1
  2 Comments
Guillaume
Guillaume on 23 Mar 2018
I do not understand first element of first row connect with remaining element in first row
An adjacency matrix is always square. So your output is not an adjacency matrix.
You need to give a much better explanation of what your input matrix represents and how to generate your not_an_adjacency_matrix output from it.
muhammad ismat
muhammad ismat on 24 Mar 2018
first row mean that user number 0 connect with user number 1, 2, 3 and there is a relation between user 1 and users 3, 5, 7 and so on. i want to obtain on adjacency matrix
0 1 1 1 0 0 0 0
1 0 0 1 0 1 0 1
1 0 0 0 1 0 1 1
1 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 1 1 0 0 0 0 0

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 24 Mar 2018
A = [0 1 2 3
1 3 5 7
2 4 6 7];
[r, c, s] = find(A);
adj = full(sparse(r,s+1,1));

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!