# Constructing an Adjacency Matrix from a Matrix/Table

7 views (last 30 days)
Mae on 2 May 2016
Commented: Steven Lord on 21 Jul 2018
I have a matrix, LinkData, whose first 2 columns contains node reference numbers, and the 3rd column contains data that the 2 nodes share. I am trying to create an Adjacency matrix using LinkData. I'm not even completely sure what an Adjacency matrix is let alone construct it. I know that it is supposed to identify which nodes are adjacent to each other (i.e. node 2 is adjacent to node 1 and 3, and node 3 is adjacent to node 2 and 4).
I have tried using accumarray but I do not think I got the right results.
accumarray(nodesPairs+1,1);
Any help would be deeply appreciated!

Walter Roberson on 2 May 2016
Close, but you should use
nodePairs = [nodePairs; fliplr(nodePairs)];
You should also give consideration to,
If you have a sufficiently recent MATLAB, then consider
G = graph(nodePairs(:,1), nodePairs(:,2));
Mohammad Bhat on 21 Jul 2018
Then, how to plot the graph..
Steven Lord on 21 Jul 2018
If you made a graph as per the last section of code in Walter's answer, just plot it.
plot(G)