0001 function newlabel = fixuplabels(oldlabel);
0002 % FIXUPLABELS : Relabel a partition vector to make labels consecutive.
0003 %
0004 % newlabel = fixuplabels (oldlabel) 
0005 %    oldlabel: vector of "labels" for the integers 1:n
0006 %    newlabel: vector representing the same partition or
0007 %              equivalence relation, but in which the labels
0008 %              are consecutive integers starting with 1.
0009 %                                 
0010 % John R. Gilbert, UCSB
0011 % Version of 25 August 2005
0012 
0013 if size(oldlabel,2) == 1
0014     oldlabel = oldlabel.';
0015 end
0016 
0017 newlabel = zeros(size(oldlabel));
0018 [s, perm] = sort(oldlabel);
0019 f = find(diff([s(1)-1 s]));
0020 newlabel(f) = 1;
0021 newlabel = cumsum(newlabel);
0022 newlabel(perm) = newlabel;