function RandomizeSmallWorld(N,k) % N: Total number of nodes % k: Degree of initial regular graph % p: Probability of rewiring node % Example: Randomize2(100,8,0.2) [Matrix,CCregular,x,y] = RegularGraphSmallWorld(N,k); for p=1:120 Prob=p./(10.^(4-p./25)); M=Matrix; for count=1:ceil(k/2)+1 for s=1:N-1 for t=s+1:N if unifSample([0 1],[(1-(Prob)) (Prob)]) == 1 if M(s,t) == 1 M(s,t) = 0; r=ceil(N*rand); while r==t || M(s,r)==1 r=ceil(N*rand); end M(s,r)=1; plot(x([s,t]),y([s,t]),'Color',[1 1 1]) hold on plot(x([s+1,t]),y([s+1,t]),'Color',[0 0 1]) pause(0.05) hold on end end end end end InfOrNan=0; for s=1:N C=M+M'; for t=1:N if C(s,t) == 0 && (s~=t) C(:,t)=0; C(t,:)=0; end end C(s,:)=0; C(:,s)=0; c=0; for u=1:N c=c+sum(C(u,:)); end e(s)=c/2; cc(s)=e(s)/sum(M(s,:)); if isinf(cc(s))==1 || isnan(cc(s))==1 cc(s)=0; InfOrNan=InfOrNan+1; % InfOrNan discounts the NaN's and Inf's % when calculating the mean below. end end CCgraph(p)=sum(cc)/(N-InfOrNan); %semilogx(Prob,CCgraph(p)/CCregular,'o') %axis([-1 1 -1 1]) hold on end e end