How can loglog graph from this code

조회 수: 2 (최근 30일)
Konstantinos koutsikakis
Konstantinos koutsikakis 2020년 12월 5일
댓글: Konstantinos koutsikakis 2020년 12월 6일
%code generte Barabasi-Albert model
N = input('number of Nodes:');
mo = input('number of initially placed nodes:');
m = input('number of nodes a new added node is connected:');
EdgeList = [];
%create a complete graph of mo nodes
for i=1:mo
for j=i+1:mo
EdgeList = [EdgeList; i j];
end
end
%grow the other N-No nodes
for t = 1:(N-mo)
j = mo+t;
%calculate degrees
degree = zeros(j-1,1);
for id = 1:j-1
degree(id) = sum(EdgeList(:,1)==id)+sum(EdgeList(:,2)==id);
end
%calculate attachment probabilities
nlinks = sum(degree);
attprob=cumsum(degree)/nlinks;
%add new links
newneighbors = [];
while length (newneighbors)<m
r = rand;
i = find(attprob>r, 1 );
newneighbors = [newneighbors i];
newneighbors = unique(newneighbors);
end
for ir = 1:m
EdgeList=[EdgeList; newneighbors(ir) j];
end
end
%From EdgeList to adjacency matrix
A = zeros(N);
[Lr, Lc] = size(EdgeList);
for i=1:Lr
A(EdgeList(i,1),EdgeList(i,2))=1;
A(EdgeList(i,2),EdgeList(i,1))=1;
end
matrix = full(A)
%plot graph
figure
g = graph(A);
h = plot(g,'NodeLabel',{});

답변 (1개)

Walter Roberson
Walter Roberson 2020년 12월 5일
You don't.
Your desired plot is of a derived value for connectivity. BBut youare instead asking to plot the actual graph.
You need to repeat the calculation multiple times for different N and for each G generated calculate the connectivity and record against N. After that create the loglog plot based on the recorded N and connectivity.
  댓글 수: 1
Konstantinos koutsikakis
Konstantinos koutsikakis 2020년 12월 6일
Ok. Can you write me the code to get the result?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Networks에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by