function c = wkmeans_update_centers ( dim, n, p, w, k, ptoc )

%% WKMEANS_UPDATE_CENTERS resets the cluster centers to the weighted data averages.
%
  wp(1:dim,1:n) = p(1:dim,1:n) * w(1:n);

  for j = 1 : k
    index = find ( ptoc(1:n) == j );
    c(1:dim,j) = sum ( wp(1:dim,index), 2 ) / sum ( w(index) );
  end

  return
end
