Guest User

Untitled

a guest
Apr 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. nodepos=xlsread('nodes');
  2. id=nodepos(:,1);
  3. x=nodepos(:,2);
  4. y=nodepos(:,3);
  5. pos=nodepos(:,2:3);
  6. % Plot nodes
  7. scatter(x(id== 0), y(id == 0), 100, 'k', '*')
  8. hold on
  9. scatter(x(id== 1), y(id == 1), 100, 'g', 's')
  10. hold on
  11. scatter(x(id== 2), y(id == 2), 120, 'r', '>')
  12. hold on
  13. scatter(x(id== 3), y(id == 3), 130, 'g', 'o')
  14. hold on
  15. scatter(x(id== 4), y(id == 4), 140, 'c', 'p')
  16. hold on
  17. scatter(x(id== 5), y(id == 5), 150, 'm', 'x')
  18. hold on
  19. scatter(x(id== 6), y(id == 6), 160, 'y', '+')
  20. hold on
  21. scatter(x(id== 7), y(id == 7), 170, 'b', 'h')
  22. hold on
  23. scatter(x(id== 8), y(id ==8), 180, 'r', '^')
  24. hold on
  25. scatter(x(id== 9), y(id == 9), 190, 'b', 'd')
  26. hold on
  27. grid on
  28. opts = statset('Display','final');
  29. [idx,C1] =
  30. kmeans(pos,2,'Distance','cityblock','Replicates',10,'Options',opts);
  31. figure;
  32. plot(pos(idx==1,1),pos(idx==1,2),'rp','MarkerSize',12)
  33. hold on
  34. plot(pos(idx==2,1),pos(idx==2,2),'bh','MarkerSize',12)
  35. plot(C1(:,1),C1(:,2),'kx','MarkerSize',15,'LineWidth',3)
  36. legend('Cluster 1','Cluster 2','Centroids','Location','NE')
  37. title 'Clusters'
  38. hold off
Add Comment
Please, Sign In to add comment