在matlab中从矩阵绘制网络或图形 [英] Draw network or graph from matrix in matlab

查看:791
本文介绍了在matlab中从矩阵绘制网络或图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何借助转换矩阵绘制网络的一系列帧?
我有一个表示图的矩阵。矩阵随迭代而改变。任何人都可以给我一个洞察,我可以使用什么功能来创建一系列的网络?

  original = [0.06 0.57 0.37 0 0; 
0.57 0.06 0.37 0 0;
0.37 0.57 0.03 0.03 0;
0 0 0.03 0.13 0.84;
0 0 0 0.84 0.16];

假设以上是所讨论的矩阵。然后,图应该是

解决方案

这个问题与此前面的查询这一个。但是这里有一个特定于你的情况的答案。

给定一个加权邻接矩阵:

pre code> original = [0.06 0.57 0.37 0 0;
0.57 0.06 0.37 0 0;
0.37 0.57 0.03 0.03 0;
0 0 0.03 0.13 0.84;
0 0 0 0.84 0.16];

您可以先定义网络中的节点数量:

  N = size(original,1); 

,然后在圆周上对应一组坐标:

  coords = [cos(2 * pi *(1:N)/ N); SIN(2 * PI *(1:N)/ N)]  - ; 

然后您可以使用 gplot

  gplot(original,coords)

并使用 text 标记顶点:

 <$ (coords(:,1)-0.1,coords(:,2)+ 0.1,num2str((1:N)'),'FontSize',14)

请注意, gplot 函数不会按连接强度加权;矩阵元素(i,j)被视为二进制,表示节点i和j之间不存在或存在链接。

How do I draw a sequence of frames of a network with the help of a transition matrix? I have a matrix that denotes a graph. The matrix changes with iterations. Can anyone give me an insight of what functions I can use to create the series of the network?

      original=[0.06    0.57    0.37    0       0;
                0.57    0.06    0.37    0       0;
                0.37    0.57    0.03    0.03    0;
                0       0       0.03    0.13    0.84;
                0       0       0       0.84    0.16];

Suppose the, above is the matrix in question. Then the graph should be

解决方案

This question is related to this earlier query and this one. But here's an answer specific to your situation.

Given a weighted adjacency matrix:

 original =    [0.06    0.57    0.37    0       0;
                0.57    0.06    0.37    0       0;
                0.37    0.57    0.03    0.03    0;
                0       0       0.03    0.13    0.84;
                0       0       0       0.84    0.16];

you can first define the number of nodes in the network:

N = size(original,1);

and then a corresponding set of coordinates on the perimeter of a circle:

coords = [cos(2*pi*(1:N)/N); sin(2*pi*(1:N)/N)]';

Then you can plot the graph using gplot:

gplot(original, coords)

and mark the vertices using text:

text(coords(:,1) - 0.1, coords(:,2) + 0.1, num2str((1:N)'), 'FontSize', 14)

Note that the gplot function does not weight the lines by connection strength; the matrix element (i,j) is treated as binary, indicating absence or presence of a link between nodes i and j.

这篇关于在matlab中从矩阵绘制网络或图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆