MATLAB is an efficient way to calculate distances between points in a graph / network using the adjacency matrix and coordinates

I have a network view in two-dimensional coordinate space. I have an adjacency matrix Adj(which is sparse) and a matrix coordinatewith x, y values ​​of all points / nodes / vertices in the graph that are drawn.

I would like to calculate the distance between these points as efficiently as possible. I would like to avoid looping through entries in the matrix and computing pair distances one by one.

+1
source share
2 answers
[n, d] = size(coordinate);
assert(d == 2);
resi = sparse(Adj * diag(1:n));
resj = sparse(diag(1:n) * Adj);
res = sparse(zeros(n));
f = find(Adj)
res(f) = sqrt((coordinate(resi(f), 1) - coordinate(resj(f), 1)) .^ 2 + (coordinate(resi(f), 2) - coordinate(resj(f), 2)) .^ 2);

EDIT: Oh, bug fixed

: , http://www.passagesoftware.net/webhelp/Coordinate_Matrix.htm

EDIT 2: , Adj ( ). ,

+2

, .

, , .

+1

All Articles