Azzera filtri
Azzera filtri

How to create random graph?

52 visualizzazioni (ultimi 30 giorni)
Deepthi B
Deepthi B il 10 Mag 2021
Commentato: Christine Tobler il 20 Dic 2021
Hi ,
I want to check whether the network that I have obtained is a small world network or not. For that I have to find out the clustering coefficient and shortest path length of a random network with the same number of nodes and links in my network. Is it possible to find out?

Risposta accettata

Christine Tobler
Christine Tobler il 10 Mag 2021
You can use
s = randi(n, e, 1);
t = randi(n, e, 1);
G = graph(s, t, [], n);
which will give you a graph with n nodes and e edges. Note that G may have multiple edges connecting the same two nodes, and may also have self-loops (edges connecting a node to itself). If you don't want repeating edges, use the following instead:
G = graph(true(n)); % Self-loops are possible
%G = graph(true(n), 'omitselfloops'); % Alternative without self-loops
p = randperm(numedges(G), e);
G = graph(G.Edges(p, :));
  5 Commenti
Norbert Cyran
Norbert Cyran il 19 Dic 2021
Why are you generating true matrix for nodes and random values for edges??
Christine Tobler
Christine Tobler il 20 Dic 2021
Hi Norbert,
The true(n) matrix is an adjacency matrix that contains all possible edges in the graph (omitting self-loops or not depending if that option is used or not). Then, I'm choosing a random subset of those edges using the randperm function.

Accedi per commentare.

Più risposte (1)

Deepthi B
Deepthi B il 13 Mag 2021
Thank You

Categorie

Scopri di più su Graph and Network Algorithms in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by