plotProgresskMeans.m 840 B

123456789101112131415161718192021222324252627
  1. function plotProgresskMeans(X, centroids, previous, idx, K, i)
  2. %PLOTPROGRESSKMEANS is a helper function that displays the progress of
  3. %k-Means as it is running. It is intended for use only with 2D data.
  4. % PLOTPROGRESSKMEANS(X, centroids, previous, idx, K, i) plots the data
  5. % points with colors assigned to each centroid. With the previous
  6. % centroids, it also plots a line between the previous locations and
  7. % current locations of the centroids.
  8. %
  9. % Plot the examples
  10. plotDataPoints(X, idx, K);
  11. % Plot the centroids as black x's
  12. plot(centroids(:,1), centroids(:,2), 'x', ...
  13. 'MarkerEdgeColor','k', ...
  14. 'MarkerSize', 10, 'LineWidth', 3);
  15. % Plot the history of the centroids with lines
  16. for j=1:size(centroids,1)
  17. drawLine(centroids(j, :), previous(j, :));
  18. end
  19. % Title
  20. title(sprintf('Iteration number %d', i))
  21. end