Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % outputs a graphical representation of the clustering solution
- function view_clusters(points, centroids)
- % TODO graphical representation coded here
- % number of points
- NP = rows(points);
- % number of clusters
- NC = rows(centroids);
- % function that leads the interval (0, 1) in the interval ((i - 1) / NC, i / NC)
- get_color = @(i) (rand(1 ,1) + i - 1) / NC;
- color = arrayfun(get_color, [randperm(NC); randperm(NC); randperm(NC)]);
- if NC == 1
- scatter3(points(:, 3), points(:, 2), points(:, 1),
- [10], [rand(1, 1) rand(1, 1) rand(1, 1)], 'filled');
- hold on;
- return
- endif
- % function that get for each column of x the row where is the min
- f = @(x) [i j] = find(x == min(x));
- % the cluster of each point
- cluster = f(reshape(norm(repmat(centroids, NP, 1) - kron(points, ones(NC, 1)), 'rows'), NC, NP));
- for i = 1 : NC
- v = points(find(cluster == i), :);
- scatter3(v(:, 3), v(:, 2), v(:, 1),
- [10], [color(i, 1) color(i, 2) color(i, 3)], 'filled');
- hold on;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement