Here is one way you can do what you want. First, generate points on the circle that you are interested in
clear;
theta=linspace(0,2*pi,31);theta=theta(1:end-1);
[x,y]=pol2cart(theta,1);
Next, if you know the pairs of nodes that are connected, you can skip this step. But in many cases, you get a connectivity matrix from other computations, and you find the indices of the connected nodes from that. Here, I've created a Boolean matrix of connections. So, if there are N
nodes, the connectivity matrix is an NxN
symmetric matrix, where if the i,j
th element is 1
, it means you have a connection from node i
to node j
and 0
otherwise. You can then extract the subscripts of the non-zero pairs to get node connections (only the upper triangle is needed).
links=triu(round(rand(length(theta))));%# this is a random list of connections
[ind1,ind2]=ind2sub(size(links),find(links(:)));
This is the connectivity matrix I generated with the code above.
Now we just need to plot the connections, one at a time
h=figure(1);clf(h);
plot(x,y,'.k','markersize',20);hold on
arrayfun(@(p,q)line([x(p),x(q)],[y(p),y(q)]),ind1,ind2);
axis equal off
which will give you a figure similar to your examples
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…