Random Walks in MATLAB
by
Mark Hoyle
05 Nov 2008
(Updated
07 Jan 2009)
Files which simulate random walks on a lattice and on a graph

RandomGraph(X,S)

function out = RandomGraph(X,S)
% Produce a random edge on a graph defined by S
%
% inputs:
% X: current node
% S: Connections matrix, S(i,j) lists the number of edges between node i
% and node j
V = S(:,X); % Node this one is connected with
Idx = find(V);
v = V(Idx)/sum(V);
s = cumsum(v);
r = rand;
ind = find(s > r);
out = Idx(ind(1));
end


Contact us