在MATLAB中绘制非二分图

时间:2017-11-20 12:30:00

标签: matlab matlab-figure graph-theory discrete-mathematics bipartite

我希望在MATLAB中绘制图形。我的图是非二分图,图的矩阵是:

A=[0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0   %1 
   1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1   %2 
   0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0   %3 
   0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0   %4 
   0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1   %5 
   1 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0   %6 
   0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0   %7 
   0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1   %8 
   0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0   %9 
   0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0   %10 
   0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1   %11 
   1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0   %12 
   0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0   %13 
   0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1   %14 
   1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0   %15 
   0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0]; %16

在MATLAB中绘制此图形时,编号为16的节点位于图形的左侧,但这应位于中心。 有没有办法设置我的矩阵,以便节点16位于中心,使图形非二分?

1 个答案:

答案 0 :(得分:1)

不确定你是如何绘制图表的,但是在我的Win10-x64 R2017b上,我得到16是距离中心最近的点:

function q47392076
A=[0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0   %1 
   1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1   %2 
   0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0   %3 
   0 0 1 0 1 0 0 0 1 0 0 0 0 0 1 0   %4 
   0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1   %5 
   1 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0   %6 
   0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0   %7 
   0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1   %8 
   0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0   %9 
   0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0   %10 
   0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1   %11 
   1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0   %12 
   0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0   %13 
   0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1   %14 
   1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0   %15 
   0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0]; %16

 G = graph(A);
 figure(); plot(G);
end

enter image description here