How can loglog graph from this code

2 vues (au cours des 30 derniers jours)
Konstantinos koutsikakis
Konstantinos koutsikakis le 5 Déc 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',{});

Réponses (1)

Walter Roberson
Walter Roberson le 5 Déc 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.
  1 commentaire
Konstantinos koutsikakis
Konstantinos koutsikakis le 6 Déc 2020
Ok. Can you write me the code to get the result?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Networks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by