function Randomize2(N,k,p) % N: Total number of nodes % k: Degree of initial regular graph % p: Probability of rewiring node % Example: Randomize2(100,8,0.2) % for p=1:90 [M,x,y,CCregular] = RegularGraph2(N,k); for count=1:ceil(k/2) for s=1:N-1 for t=s+1:N if unifSample([0 1],[(1-p) p]) == 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,t]),y([s,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=sum(cc)/(N-InfOrNan); %CCgraph(p)=sum(cc)/(N-InfOrNan); CCgraph/CCregular %semilogx(p/100,CCgraph(p)/CCregular,'o') %hold on % end end