如何在Matlab中绘制网络?

如何在Matlab中绘制网络?,matlab,graph,plot,graph-theory,graph-visualization,Matlab,Graph,Plot,Graph Theory,Graph Visualization,我在Matlab中有一个矩阵a,其尺寸mx2,每行包含两个节点的标签,显示网络中的直接链接,例如: 如果网络有4个节点,则矩阵A可以是A=[12;13;21;24;32;41;42],其中第一行表示存在从1到2的链接,第二行表示存在从1到3的链接,等等 你能给我一个快速的方法从一个网络中提取网络吗 n = max(A(:)); %// number of nodes theta = linspace(0,2*pi,n+1); %// the nodes will be on a circle t

我在Matlab中有一个矩阵
a
,其尺寸
mx2
,每行包含两个节点的标签,显示网络中的直接链接,例如:

如果网络有
4个
节点,则矩阵
A
可以是
A=[12;13;21;24;32;41;42]
,其中第一行表示存在从
1
2
的链接,第二行表示存在从
1
3
的链接,等等

你能给我一个快速的方法从一个网络中提取网络吗

n = max(A(:)); %// number of nodes
theta = linspace(0,2*pi,n+1); %// the nodes will be on a circle
theta = theta(1:end-1);
x = cos(theta); %// x coordinates of nodes
y = sin(theta); %// y coordinates of nodes
plot(x, y, 'ro') %// plot nodes
hold on
plot(x(A).', y(A).', 'b-') %// plot edges
axis image
axis(1.2*[-1 1 -1 1])
set(gca,'xtick',[],'ytick',[])

使用内置功能的替代解决方案

adj=accumarray(A,1)
n=size(adj,1); % number of nodes
coord=[cos((1:n).'*(2*pi/n)),sin((1:n).'*(2*pi/n))] % points on a circle for nodes
gplot(adj,coord)

对于大型网络,邻接矩阵可以使用accumarray(A,1,[],[],[],0,true)稀疏生成。
如果您希望链接具有方向性,并且有生物信息学工具箱,则可以创建
biograph
对象。这还允许使用标识字符串标记节点(如果需要),请参阅帮助文件。如果没有,它们将被称为“节点1”、“节点2”等。您需要将链接列表转换为邻接矩阵-@RTL如果
accumarray
版本,您还可以使用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

您可能还对Matgraph感兴趣,Matlab工具箱用于图形操作:


MatLab>R2015b现在有了

A
就是您所说的边缘列表

plot(digraph(A(:,1),A(:,2))

将绘制网络。

您有权访问生物信息学工具箱吗?是的,我有权访问它在Matlab 2015b中引入了函数
图形
。是否可以添加链接的方向?您可以使用
注释
而不是
绘图
。问题在于,
注释
使用了标准化的轴单位,这很麻烦