<p>If your graph is connected, a way to construct the array xy to pass to gplot is as v(:,[2 3]) where v is the matrix of eigenvectors of the Laplacian matrix, ordered from smallest eigenvalues to largest. So we can do it this way:</p>

<pre><code>L=diag(sum(A))-A;
[v,~]=eig(L);
xy=v(:,[2 3])
gplot(A,xy)
</code></pre>

<p>or this way:</p>

<pre><code>L=diag(sum(A))-A;
[v,~]=eigs(L,3,'SM')
xy=v(:,[2 1])
gplot(A,xy)
</code></pre>

<p>The second one should be more efficient, especially if A is big.</p>

<p>This will create a nice plot under normal circumstances. This is not guaranteed to work; in particular, it is not guaranteed to assign different nodes different coordinates. But usually it works pretty nicely.</p>

<p>Some theory behind this can be found at <a href="https://arxiv.org/pdf/1311.2492.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/1311.2492.pdf</a></p>
How to graph adjacency matrix using MATLAB
<p>I want to create a plot showing connections between nodes from an adjacency matrix like the one below.</p>

<p><img src="https://i.stack.imgur.com/WyV7Q.png" alt="enter image description here"></p>

<p><a href="http://www.mathworks.com/help/matlab/ref/gplot.html" rel="nofollow noreferrer">gplot</a> seems like the best tool for this. However, in order to use it, I need to pass the coordinate of each node. The problem is that I don't know where the coordinates should be, I was hoping the function would be capable of figuring out a good layout for me.</p>

<p>For example here's my output using the following arbitrary coordinates:</p>

<pre><code> A = [1 1 0 0 1 0;
      1 0 1 0 1 0;
      0 1 0 1 0 0;
      0 0 1 0 1 1;
      1 1 0 1 0 0;
      0 0 0 1 0 0];

 crd = [0 1;
        1 1;
        2 1;
        0 2;
        1 2;
        2 2];

 gplot (A, crd, "o-");
</code></pre>

<p><img src="https://i.stack.imgur.com/JKtD3.png" alt="enter image description here"></p>

<p>Which is hard to read, but if I play around with the coordinates a bit and change them to the following it becomes much more readable.</p>

<pre><code>   crd = [0.5 0;
         0 1;
         0 2;
         1 2;
         1 1;
         1.5 2.5];
</code></pre>

<p><img src="https://i.stack.imgur.com/VRrwp.png" alt="enter image description here"></p>

<p>I don't expect perfectly optimized coordinates or anything, but how can I tell MATLAB to automatically figure out a set of coordinates for me that looks okay using some sort of <a href="http://cs.brown.edu/~rt/gdhandbook/chapters/force-directed.pdf" rel="nofollow noreferrer">algorithm</a> so I can graph something that looks like the top picture.</p>

<p>Thanks in advance.</p>