n = [ 98 1547; 641 1108 ; 124 476 ; 508 507 ; 619 512 ; 746 531 ; 342 507 ; 439 1018 ; 195 1099 ; 550 843; 721 1651; 384 1547; 305 2364 ; 175 1649]
k = 7;
b = nchoosek(1:length(n),k);
c1 = zeros(size(b,1),1);
c2 = zeros(size(b,1),1);
c3 = zeros(size(b,1),1);
c4 = zeros(size(b,1),1);
c5 = zeros(size(b,1),1);
for i = 1 : size(b,1)
subb = b(i,:);
subn = n(subb,:);
subd = delaunay(subn(:,1),subn(:,2));
for j = 1 : size(b,2)-1
for k = j+1 : size(b,2)
c1(i) = c1(i) + sqrt((subn(j,1)-subn(k,1))^2 + ...
(subn(j,2)-subn(k,2))^2);
end
end
for j = 1 : size(subd,1)
c2(i) = c2(i) + ...
( sqrt((subn(subd(j,1),1)-subn(subd(j,2),1))^2 ...
+ (subn(subd(j,1),2)-subn(subd(j,2),2))^2) ...
+ sqrt((subn(subd(j,3),1)-subn(subd(j,2),1))^2 ...
+ (subn(subd(j,3),2)-subn(subd(j,2),2))^2) ...
+ sqrt((subn(subd(j,1),1)-subn(subd(j,3),1))^2 ...
+ (subn(subd(j,1),2)-subn(subd(j,3),2))^2) )^2;
end
for j = 1 : size(subd,1)
c3(i) = c3(i) + polyarea(subn(subd(j,:),1),subn(subd(j,:),2));
end
for ka=1:size(subd,1)
for k2=1:3
c5(i)= c5(i) + ...
sqrt(((subn(subd(ka,k2),1)-subn(subd(ka,mod(k2,3)+1),1))^2)+...
((subn(subd(ka,k2),2)-subn(subd(ka,mod(k2,3)+1),2))^2));
end
end
CVHL=convhull(subn(:,1),subn(:,2));
for kx=1:length(CVHL)-1
c5(i)=c5(i) + ...
sqrt(((subn(CVHL(kx),1)-subn(CVHL(kx+1),1))^2)+...
((subn(CVHL(kx),2)-subn(CVHL(kx+1),2))^2));
end
end
c4 = c2/max(c2) + c3/max(c3);
[~,e1] = max(c1);
[~,e2] = max(c2);
[~,e3] = max(c3);
[~,e4] = max(c4);
[~,e5] = max(c5);
f1 = b(e1,:);
f2 = b(e2,:);
f3 = b(e3,:);
f4 = b(e4,:);
f5 = b(e5,:);
figure;
subplot(2,3,1);
plot(n( :,1),n(: ,2),'bo','MarkerSize',15);
title('Starting Point Set'); axis equal;
subplot(2,3,2);
plot(n( :,1),n(: ,2),'bo','MarkerSize',15); hold on;
plot(n(f1,1),n(f1,2),'rx','MarkerSize',15); hold off;
title(sprintf('"Best" %d Points (M-1)',k)); axis equal;
subplot(2,3,3);
plot(n( :,1),n(: ,2),'bo','MarkerSize',15); hold on;
plot(n(f2,1),n(f2,2),'rx','MarkerSize',15); hold off;
title(sprintf('"Best" %d Points (M-2)',k)); axis equal;
subplot(2,3,4);
plot(n( :,1),n(: ,2),'bo','MarkerSize',15); hold on;
plot(n(f3,1),n(f3,2),'rx','MarkerSize',15); hold off;
title(sprintf('"Best" %d Points (M-3)',k)); axis equal;
subplot(2,3,5);
plot(n( :,1),n(: ,2),'bo','MarkerSize',15); hold on;
plot(n(f4,1),n(f4,2),'rx','MarkerSize',15); hold off;
title(sprintf('"Best" %d Points (M-4)',k)); axis equal;
subplot(2,3,6);
plot(n( :,1),n(: ,2),'bo','MarkerSize',15); hold on;
plot(n(f5,1),n(f5,2),'rx','MarkerSize',15); hold off;
title(sprintf('"Best" %d Points (M-5)',k)); axis equal;
2 Comments
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/42622-how-can-i-choose-a-subset-of-k-points-the-farthest-apart#comment_87457
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/42622-how-can-i-choose-a-subset-of-k-points-the-farthest-apart#comment_87457
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/42622-how-can-i-choose-a-subset-of-k-points-the-farthest-apart#comment_87466
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/42622-how-can-i-choose-a-subset-of-k-points-the-farthest-apart#comment_87466
Sign in to comment.