function [circularPositions] = circulargraph2(matrix,labels, plotHandle);
% circulargraph2(matrix,labels)
% Author: Marcus Kaiser Date: 3 July 2006
% Modified by: James Allen Date: July 2006
% Function to plot a circular connectivity graph using the connectivity
% matrix 'matrix' (numerical matrix where 0 = no connection, >0 = a
% connection), label the points using cell array 'labels', using the
% supplied plot handle
NODES = length(matrix);
circularPositions = zeros(NODES,2);
step = 2 * pi / NODES;
% Calculate the circular positions of nodes
for i=1:NODES
circularPositions(i,:) = [cos(i*step) sin(i*step)];
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MODIFICATION by James Allen 20.7.06 -
axes(plotHandle);
hold on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot the nodes
plot(circularPositions(:,1),circularPositions(:,2),'r.');
% Plot the labels and arcs
for i=1:NODES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MODIFICATION by James Allen 20.7.06 - plot text labels so they do not overlap
% with graph. Ones to left plotted with alignment left, those to right
% with alignment right
if (i <= NODES / 4) | (i > 3 * (NODES / 4))
text(circularPositions(i,1),circularPositions(i,2),labels(i), 'horizontalalignment', 'left');
elseif NODES / 4 < i <= 3 * (NODES / 4)
text(circularPositions(i,1),circularPositions(i,2),labels(i), 'horizontalalignment', 'right');
end
% END OF MODIFICATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for j=1:NODES
if matrix(i,j) ~= 0
line([circularPositions(i,1) circularPositions(j,1)],[circularPositions(i,2) circularPositions(j,2)],'Color',[0 0 0.5]);
end
end
end
axis off;
hold off;
return;