Code covered by the BSD License  

Highlights from
Random Walks in MATLAB

image thumbnail

Random Walks in MATLAB


Mark Hoyle (view profile)


05 Nov 2008 (Updated )

Files which simulate random walks on a lattice and on a graph

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

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));


Contact us