-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.m
More file actions
53 lines (33 loc) · 1.1 KB
/
main.m
File metadata and controls
53 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
% Main execution file
n_points = 100;
points = xlsread('data.xls');
points_x = points(:, 1);
points_y = points(:, 2);
n_clusters = 10;
n_iterations = 100;
[~, ~, cluster_assignment] = kmeans(points_x, points_y, n_clusters, n_iterations);
cluster_points_x = {};
cluster_points_y = {};
for cluster_index = 1:n_clusters
points_in_cluster = (cluster_index == cluster_assignment);
cluster_points_x{cluster_index} = points_x(points_in_cluster);
cluster_points_y{cluster_index} = points_y(points_in_cluster);
end
cluster_colors = choose_random_colors(n_clusters);
figure(1)
clf
subplot(1, 2, 1)
plot(points_x, points_y, '.')
axis square
subplot(1, 2, 2)
hold on
for cluster_index = 1:n_clusters
x = cluster_points_x{cluster_index};
y = cluster_points_y{cluster_index};
[convhull_x, convhull_y] = convhull_points(x, y);
plot(convhull_x, convhull_y, 'k')
[visit_order, ~] = find_shortest_path(x, y, -1); % final argument not yet used
plot(x(visit_order), y(visit_order), 'color', cluster_colors(cluster_index, :), 'linewidth', 2)
end
hold off
axis square