필터 지우기
필터 지우기

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 (최근 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