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 次查看(过去 30 天)
[G]= function(n) . . . return

采纳的回答

Guillaume
Guillaume 2018-2-9
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 个评论
Guillaume
Guillaume 2018-2-9
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 2018-2-9
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.

请先登录,再进行评论。

更多回答(1 个)

M Shaka
M Shaka 2018-2-9
thanks

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by