2

I am looking to draw a graph in MATLAB. My graph is non-bipartite and the matrix for the graph is:

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

When this graph is drawn in MATLAB, the node numbered 16 is to the left of the graph but this should be in the centre. Is there a way to set up my matrix so that the node 16 is in the centre making the graph non-bipartite?

Dev-iL
  • 23,742
  • 7
  • 57
  • 99

1 Answers1

1

Not sure how you're plotting the graph, but on my Win10-x64 R2017b I get that 16 is the closest point to the center:

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

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
  • I get the same result (R2017a, Win 7) – Luis Mendo Nov 20 '17 at 17:20
  • I have posted again to show what comes up on my graph. What I am loking for is to put the point 16 in the centre. When I used the code suggested it gives me an error. Thanks again for your help! – Colm Mc Namara Nov 21 '17 at 10:45
  • @ColmMcNamara the `graph` function was "**Introduced in R2015b**". If your MATLAB version is older than this, you will need to update it to use the above solution. In any case, you should 1) mention your MATLAB version in the question, 2) when encountering an error - tell us what it is. – Dev-iL Nov 21 '17 at 11:04