Code covered by the BSD License  

Highlights from
Estimating the number of clusters via System Evolution

from Estimating the number of clusters via System Evolution by Kaijun Wang
estimate number of clusters for far clusters, small-larger clusters, slightly overlapping clusters

energydiff_allclusters(Dist,labels,km,dc)
function [ind,ind2,Edist,Esep] = energydiff_allclusters(Dist,labels,km,dc)
% finding energies for all clusters

ind = zeros(km(1),km(1));
ind2 = zeros(km(1),km(1));
Q = ind2cluster(labels(:,km(1)));      % fetch labels of clusters
k = 0;
Edist = [];
Esep = [];
for i = 1:km(1)
  for j = i+1:km(1)
     k = k+1;
     [A1,A2,B1,B2,A3,B3] = cluster_model(Dist,Q{i},Q{j});
     [Ep Em] = energy_compute(Dist,A1,A2,B1,B2,A3,B3,dc+3);
     Edist(k,:) = [i j Ep];
     Esep(k,1:2) = [i j];
     ind(i,j) = Ep(:,4);     % net border distances are stored
     if Ep(:,4) < 0           % separable degrees are stored if Ep(:,4)<0
       ind2(i,j) = Em(:,3)-max(Em(:,1:2)); 
       Esep(k,3:6) = Em;
       Esep(k,6) = ind2(i,j);
     end
  end
end

Contact us at files@mathworks.com