Azzera filtri
Azzera filtri

Hi every one, I am a little bit new in matlab I would like to generate directed random graph using Matlab. That is a random directed graph with n nodes . That is How to generate a random network with a certain number of nodes in Matlab

5 visualizzazioni (ultimi 30 giorni)
[G]= function(n) . . . return

Risposta accettata

Guillaume
Guillaume il 9 Feb 2018
With so little information the only thing we can do is point you to digraph. What is random about your graph? Is the number of edges fixed.
g = digraph(randi([0 n], n))
will generate a random directed graph with n node. It's unlikely to be pretty as it will have many edges (n*(n-1) edges on average).
  5 Commenti
Guillaume
Guillaume il 9 Feb 2018
As per the doc (link in my answer) digraph requires at least R2015b.
If you want to work with graphs, I strongly recommend upgrading to at least R2015b as it introduced lots of graph functions including the ability of easily plotting graphs.
For example, in just two lines:
g = digraph(max(randi([-60 10], 10), 0));
plot(g);
I've generated this:
Steven Lord
Steven Lord il 9 Feb 2018
FYI the sprand and sprandsym functions are also useful in generating random networks. That may be an easier to understand alternative than calling max(randi(... to generate a matrix with roughly a specific proportion of nonzero elements.

Accedi per commentare.

Più risposte (1)

M Shaka
M Shaka il 9 Feb 2018
thanks

Categorie

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

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by