用节点之间的链接绘制圆形编队的节点网络 [英] Drawing a network of nodes in circular formation with links between nodes
问题描述
我想绘制一个节点的圆形图,其中某些节点之间有链接。以下是一些来自社交网络图的例子:
MATLAB如何做到这一点?是否有可能没有安装一个单独的软件包?
这是一种你可以做你想做的事情的方法。首先,在您感兴趣的圈子上生成积分
clear;
theta = linspace(0,2 * pi,31); theta = theta(1:end-1);
[x,y] = pol2cart(theta,1);
接下来,如果您知道已连接的节点对,则可以跳过此步骤。但是在很多情况下,您可以从其他计算中获得连接矩阵,并且可以从中找到连接节点的索引。在这里,我创建了一个布尔连接矩阵。因此,如果存在 N
节点,则连接矩阵是 NxN
对称矩阵,其中如果 i,j
th元素是 1
,这意味着你有一个来自节点 i $ c $的连接c>到节点
j
和 0
否则。然后,您可以提取非零对的下标以获得节点连接(仅需要上三角形)。
链接= triu(round(rand(length(theta))));%#这是一个随机的连接列表
[ind1,ind2] = ind2sub(size(links),find(links(:)));
这是我用上面的代码生成的连接矩阵。
现在我们只需要绘制一个连接,一次一个
h = figure(1); clf(h);
plot(x,y,'。k','markersize',20);持有
arrayfun(@(p,q)line([x(p),x(q)], [Y(p)中,y(q)]),IND1,IND2);
轴相等于
这会给你一个与你的例子相似的数字
I would like to draw a circular graph of nodes where certain nodes have a link between them. Here are a few examples from social network graphs:
example1 http://wrightresult.com/wp-content/uploads/social-network-circle5-lg.jpg
example3 http://twit88.com/blog/wp-content/uploads/2008/07/windowslivewriterjung-ed84jung-2.jpg
How can this be done with MATLAB? Is it possible without installing a separate package?
Here is one way you can do what you want. First, generate points on the circle that you are interested in
clear;
theta=linspace(0,2*pi,31);theta=theta(1:end-1);
[x,y]=pol2cart(theta,1);
Next, if you know the pairs of nodes that are connected, you can skip this step. But in many cases, you get a connectivity matrix from other computations, and you find the indices of the connected nodes from that. Here, I've created a Boolean matrix of connections. So, if there are N
nodes, the connectivity matrix is an NxN
symmetric matrix, where if the i,j
th element is 1
, it means you have a connection from node i
to node j
and 0
otherwise. You can then extract the subscripts of the non-zero pairs to get node connections (only the upper triangle is needed).
links=triu(round(rand(length(theta))));%# this is a random list of connections
[ind1,ind2]=ind2sub(size(links),find(links(:)));
This is the connectivity matrix I generated with the code above.
Now we just need to plot the connections, one at a time
h=figure(1);clf(h);
plot(x,y,'.k','markersize',20);hold on
arrayfun(@(p,q)line([x(p),x(q)],[y(p),y(q)]),ind1,ind2);
axis equal off
which will give you a figure similar to your examples
这篇关于用节点之间的链接绘制圆形编队的节点网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!