function v = kmeans_variance ( dim, n, p, k, c, ptoc )

%% KMEANS_VARIANCE computes the variance of the K-means clustering.
%
  v = 0.0;
  for i = 1 : n
    j = ptoc(i);
    v = v + ( norm ( p(1:dim,i) - c(1:dim,j) ) )^2;
  end

  return
end
