genrgg.m 500 Bytes
Newer Older
mrebollo committed
1 2 3 4 5 6 7 8 9 10 11 12
function [A, dmat ] = genrgg(n, coor, dist)
%GENRGG	Generates a Random Geometric Graph
%	A rangom reometric graph is a random graph in the unit square [0,1]
%	where nodes are linked when they are closer that a minimum distance dist
    dmat = squareform(pdist(coor));   %matrix with distances (think about handle it in a vector)
    if nargin < 3
        dist = min(max(dmat));
    end
    [row,col] = find( dmat < dist );
    A = spones(sparse([row;col],[col;row],1,n,n));
    A(1:n+1:n*n) = 0;
end