function rankclock(rank,varargin) % RANKCLOCK - Make rank clock plot % % RANKCLOCK(rank, options) plots the diagram based on the rank data in the matrix rank. Each row % contains the subsequent rank values for one entity. NaN is allowed and will produce breaks % in the plot. % % Options can be added: % 'labels' takes the following array of numbers as numerical labels for the spokes. % 'plabels' followed by a cell array allows labelling the entities % 'gap' leaves open a gap between the last and first spoke % 'mark' followed by an array marks the nonzero entries % 'markwidth' followed by a number sets the line width of marked entries % 'whitening' followed by a number in [0,1] sets the greyout of unmarked entries. % 'rect' makes the plot rectangular % 'invert' turns the plot inside out. % 'background' followed by a [r g b] array sets the bacground color. % plotlabels=0; gap=0; mark=0; linew=2; rect=0; invert=0; linelabels=0; whitening=.75; background=0; for j=1:size(varargin,2) if (strcmp(varargin{j},'labels')==1) label=varargin{j+1}; plotlabels=1; end if (strcmp(varargin{j},'plabels')==1) plabel=varargin{j+1}; linelabels=1; end if (strcmp(varargin{j},'gap')==1) gap=1; end if (strcmp(varargin{j},'mark')==1) mark=1; marked=varargin{j+1}; end if (strcmp(varargin{j},'markwidth')==1) linew=varargin{j+1}; end if (strcmp(varargin{j},'whitening')==1) whitening=varargin{j+1}; end if (strcmp(varargin{j},'rect')==1) rect=1; end if (strcmp(varargin{j},'invert')==1) rank=max(rank(:))-rank+1; end if (strcmp(varargin{j},'background')==1) background=1; bc=varargin{j+1}; end end N=size(rank,1); M=size(rank,2); theta=-pi/2+(0:(M-1))*2*pi/(M-1+gap); firstrank=zeros(N,1); first=zeros(N,1); for i=1:N j=1; while(firstrank(i)==0) if (~isnan(rank(i,j))) firstrank(i)=rank(i,j); first(i)=j; continue end j=j+1; end end col=jet(max(rank(:))); col=col(firstrank,:); if (mark==1) for i=1:N if (marked(i)==1) 1, else col(i,:)=col(i,:)*(1-whitening)+whitening; end end end clf hold on axis off axis square if (background==1) R=max(rank(:))*1.3; if (rect==0) l=patch(R*[-1; 1; 1; -1],R*[-1; -1; 1; 1],bc) axis([-R R -R R]*1.001) else l=patch([min(theta); max(theta); max(theta); min(theta)],max(rank(:))*[0; 0; 1; 1],bc) axis([min(theta) max(theta(:)) 0 R]) end end for i=1:N if (rect==0) l=polar(-theta,rank(i,:)); else l=plot(theta,rank(i,:)); end set(l,'Color',col(i,:)); if (mark==1) if (marked(i)==1) set(l,'LineWidth',linew); end end end for i=1:N if (linelabels==1 & (mark==0 | (mark == 1 & marked(i)==1))) if (rect==0) text(rank(i,first(i))*cos(-theta(first(i))),rank(i,first(i))*sin(-theta(first(i))),char(plabel(i))); else text(theta(first(i)),rank(i,first(i)),char(plabel(i))); end end end if (plotlabels==1) N2=max(rank(:))*1.1; for i=1:M if (rect==0) text(N2*cos(-theta(i)),N2*sin(-theta(i)),sprintf('%d',label(i))); else text(theta(i),-2,sprintf('%d',label(i))); end end end