How can loglog graph from this code

2 ビュー (過去 30 日間)
Konstantinos koutsikakis
Konstantinos koutsikakis 2020 年 12 月 5 日
%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 Center および File ExchangeNetworks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by