1个回答
展开全部
%% 随机产生N个点
N = 5;
A = randint(N,2,[1 20]);
for p = 1:N
x = A(p,1);
y = A(p,2);
plot(x,y,'o');
hold on
text(x+0.5,y+0.5,num2str(p));
end
axis([0 30 0 30]);
axis equal
grid on
dd = pdist(A)';
mind = min(dd);
id = find(dd==mind);
ppp = [nchoosek(1:N,2) pdist(A)'];
for p = 1:length(id)
k = id(p);
ppp(k,:)
x1 = A(ppp(k,1),1);
y1 = A(ppp(k,1),2);
x2 = A(ppp(k,2),1);
y2 = A(ppp(k,2),2);
plot(x1,y1,'ro');
plot(x2,y2,'ro');
line([x1 x2],[y1 y2]);
text(x1+1,y1-1,['mind = ' num2str(dd(k))]);
end
hold off
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询