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 views (last 30 days)
[G]= function(n) . . . return

Accepted Answer

Guillaume
Guillaume on 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 Comments
Guillaume
Guillaume on 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 on 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.

Sign in to comment.

More Answers (1)

M Shaka
M Shaka on 9 Feb 2018
thanks

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!