Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. function Y = k_means_standard(houses, wares)
  2.  
  3. W = length(wares);
  4. H = length(houses);
  5. Y = houses;
  6.  
  7.  
  8. ware_positions = zeros(2, W);
  9. for w = 1:W
  10. ware_positions(:,w) = wares(w).position;
  11. end
  12.  
  13. houses_positions = zeros(2, H);
  14. for h = 1:H
  15. houses_positions(:,h) = houses(h).position;
  16. end
  17.  
  18. for h = 1:length(houses)
  19. dist = distance(ware_positions, repmat(houses_positions(:,h), 1, W));
  20. [min_dist, index] = min(dist)
  21. Y(h).closest_ware = index;
  22. Y(h).closest_ware_distance = min_dist;
  23. end
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement