How can loglog graph from this code
Show older comments
%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',{});

Answers (1)
Walter Roberson
on 5 Dec 2020
0 votes
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 Comment
Konstantinos koutsikakis
on 6 Dec 2020
Categories
Find more on Networks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!