如何在Matlab中绘制网络? [英] How to draw networks in Matlab?

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

问题描述

在维度为 mx2 的Matlab中,有一个矩阵 A ,每行包含显示两个节点的标签在网络中的直接链接,例如:如果网络具有 4 节点,则矩阵

> A 可以是 A = [1 2; 1 3; 2 1; 2 4; 3 2; 4 1; 4 2] ,其中第一行表示存在从 1 2 ,第二行意味着存在从 1 3 等的链接。



您能否建议我从A中快速绘制网络?

希望链接具有方向性,并拥有Bioinformatics工具箱,您可以创建一个 biograph 对象。如果您愿意,也可以使用标识字符串标记节点,请参阅帮助文件。如果不是,他们将被称为节点1,节点2等。您需要将链接列表转换为邻接矩阵 - @RTL给出了 accumarray 版本,你也可以使用sub2ind:

  N = 4; 
adj =零(N);
adj(sub2ind([N,N],A(:,1),A(:,2)))= 1;

bg = biograph(adj); %make biograph object
dolayout(bg); %自动计算节点的位置
view(bg); %它在锡


上所说的

I have a matrix A in Matlab of dimension mx2 that contains in each row the labels of two nodes showing a direct link in a network, e.g.:

if the network has 4 nodes the matrix A could be A=[1 2; 1 3; 2 1; 2 4; 3 2; 4 1; 4 2], where the first row means that there is a link from 1 to 2, the second row means that there is a link from 1 to 3, etc.

Could you suggest me a quick way to draw the network from A?

解决方案

If you want the links to be directional, and have the Bioinformatics toolbox, you can create a biograph object. This also allows for labelling the nodes with identification strings if you so desire, see the help file. If not they'll be called "Node 1", "Node 2", etc. You'll need to convert your list of links to an adjacency matrix - @RTL gave the accumarray version, you can also use sub2ind:

N = 4;
adj = zeros(N);
adj(sub2ind([N,N], A(:,1),A(:,2))) = 1;

bg = biograph(adj);  % make biograph object
dolayout(bg);   % automatically calculate positions for nodes
view(bg); % what it says on the tin

这篇关于如何在Matlab中绘制网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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