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

2 visualizaciones (últimos 30 días)
[G]= function(n) . . . return

Respuesta aceptada

Guillaume
Guillaume el 9 de Feb. de 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 comentarios
Guillaume
Guillaume el 9 de Feb. de 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 el 9 de Feb. de 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.

Iniciar sesión para comentar.

Más respuestas (1)

M Shaka
M Shaka el 9 de Feb. de 2018
thanks

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by