A1 = [42,21];
A2 = [30,64];
A3 = [87,32];
A4 = [2,96];
A5 = [77,73];
A6 = [97,41];
A7 = [99,74];
A8 = [79,27];
A9 = [44,44];
A10 = [50,93];
for p = 1:10 % 放进一个矩阵内方便操作
c = num2str(p);
s = ['A(p,:) = A' c ';'];
eval(s);
end
% scatter(A(:,1),A(:,2));
for p = 1:10
c = num2str(p);
plot(A(p,1),A(p,2),'ko');
hold on
axis([-10 110 -10 110]);
text(A(p,1)+2,A(p,2)-1,c);
end
% 需要的顺序为A1-A8-A3-A6-A7-A5-A10-A4-A2-A9-A1
sx = [1 8 3 6 7 5 10 4 2 9 1];
for p = 1:length(sx)-1
P1 = A(sx(p),:);
P2 = A(sx(p+1),:);
line([P1(1) P2(1)],[P1(2) P2(2)],'color','r');
end
hold off
追问十分感谢
不过能不能把横纵坐标的间距设置为10呢?
追答
A1 = [42,21];
A2 = [30,64];
A3 = [87,32];
A4 = [2,96];
A5 = [77,73];
A6 = [97,41];
A7 = [99,74];
A8 = [79,27];
A9 = [44,44];
A10 = [50,93];
for p = 1:10 % 放进一个矩阵内方便操作
c = num2str(p);
s = ['A(p,:) = A' c ';'];
eval(s);
end
% scatter(A(:,1),A(:,2));
for p = 1:10
c = num2str(p);
plot(A(p,1),A(p,2),'ko');
hold on
axis([-10 110 -10 110]);
text(A(p,1)+2,A(p,2)-1,c);
end
set(gca,'xtick',0:10:100,'ytick',0:10:100);
% 需要的顺序为A1-A8-A3-A6-A7-A5-A10-A4-A2-A9-A1
sx = [1 8 3 6 7 5 10 4 2 9 1];
for p = 1:length(sx)-1
P1 = A(sx(p),:);
P2 = A(sx(p+1),:);
line([P1(1) P2(1)],[P1(2) P2(2)],'color','r');
end
hold off