matlab画散点连线图
我现在有十个坐标,想要用matlab把他们按顺序连起来,求高手帮忙解决下了,谢谢了。坐标如下:A1[42,21],A2[30,64],A3[87,32],A4[2,96]...
我现在有十个坐标,想要用matlab把他们按顺序连起来,求高手帮忙解决下了,谢谢了。坐标如下:
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]
需要的顺序为A1-A8-A3-A6-A7-A5-A10-A4-A2-A9-A1 展开
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]
需要的顺序为A1-A8-A3-A6-A7-A5-A10-A4-A2-A9-A1 展开
1个回答
展开全部
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询