How can loglog graph from this code

2 Ansichten (letzte 30 Tage)
Konstantinos koutsikakis
Konstantinos koutsikakis am 5 Dez. 2020
%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',{});

Antworten (1)

Walter Roberson
Walter Roberson am 5 Dez. 2020
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.

Kategorien

Mehr zu Networks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by