So you basically want to create an adjacency matrix from an adjacency list of edges? The number of your edges (i.e. your FID
column) is irrelevant so I'm assuming your input data is of the form
edges = [1 2
1 4
2 3
2 4]
Now the first column of edges is the rows of your adjacency matrix and the second is the columns (or vice versa, it doesn't matter since your matrix is symmetrical)
The simplest solution is to use linear index which you would get via the sub2ind
function:
adj = inf(size(edges,2));
idx = sub2ind(size(adj),edges(:,1), edges(:,2))
adj(idx) = 1;
I suspect your edges
matrix will already be symmetrical but if it's not then just use
edges_sym = [edges; fliplr(edges)]
instead of edges