How to generate random graph of n vertices with random connections with specified number of Edge in matlab

16 visualizzazioni (ultimi 30 giorni)
Though i have used the below code for generating the random graph of n vertices with random connections, it is even choosing the number of edges randomly. Could some one please help me to find the solution for this?
G = round(rand(n));
G = triu(G) + triu(G,1)';
G = G - diag(diag(G));
Example: n = 5; number of edges = 10
Response:
0 1 0 1 0
1 0 1 0 0
1 1 0 1 0
0 0 1 0 1
0 1 0 0 0

Risposta accettata

Matt J
Matt J il 3 Dic 2021
Modificato: Matt J il 3 Dic 2021
n=5; %number of nodes
e=10; %number of edges
T=table(randi(n,e,2),'Var',{'EndNodes'});
G=graph(T);
plot(G)
  6 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

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

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by