function c = kmeans_update_centers ( dim, n, p, k, ptoc )

%% KMEANS_UPDATE_CENTERS resets the cluster centers to the data averages.
%
  for j = 1 : k
    index = find ( ptoc(1:n) == j );
    nj = length ( index );
    c(1:dim,j) = sum ( p(1:dim,index), 2 ) / nj;
  end

  return
end
