如何创建随机图?

94次观看(最近30天)
你好 ,
I want to check whether the network that I have obtained is a small world network or not. For that I have to find out the clustering coefficient and shortest path length of a random network with the same number of nodes and links in my network. Is it possible to find out?

接受的答案

克里斯汀·托布勒(Christine Tobler)
您可以使用
s = randi(n,e,1);
t = randi(n,e,1);
g =图(s,t,[],n);
这将为您提供带有n个节点和e边缘的图形。请注意,G可能具有连接相同两个节点的多个边缘,并且也可能具有自动宽(将节点连接到自身的边缘)。如果您不想重复边缘,请改用以下内容:
g =图(true(n));% Self-loops are possible
%G = graph(true(n), 'omitselfloops'); % Alternative without self-loops
p = randperm(numedges(g),e);
g = graph(g.edges(p,:));
5条评论
克里斯汀·托布勒(Christine Tobler)
嗨,诺伯特,
真正的(n)矩阵是一个邻接矩阵,反对tains all possible edges in the graph (omitting self-loops or not depending if that option is used or not). Then, I'm choosing a random subset of those edges using the randperm function.

登录发表评论。

更多答案(1)

Deepthi b
Deepthi b 2021年5月13日
谢谢你

社区寻宝

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

Start Hunting!