How to plot lines between points

2 次查看(过去 30 天)
I Have a matrix of routes (11x11)
1 5 46 1 0 0 0 0 0 0 0
1 41 10 40 73 13 27 1 0 0 0
1 31 75 49 30 16 58 14 28 53 1
1 68 36 20 55 9 47 35 1 0 0
1 7 34 24 57 64 1 0 0 0 0
1 4 45 25 50 17 52 1 0 0 0
1 59 11 32 26 56 19 51 33 18 1
1 2 44 42 43 65 23 62 22 29 1
1 48 37 70 72 61 71 21 38 6 1
1 76 69 3 63 74 1 0 0 0 0
1 39 12 66 67 60 15 54 8 1 0
This means that the vehicle will go from 1 to 5 to 46...and return to 1 again. There are 11 different routes.
I have plotted already
for i=1:N
pltx(i)=z(i,2)
plty(i)=z(i,3)
pltz(i)=z(i,1)
end
n=numel(pltx);
plot( graph(1:n,1:n),'LineStyle','none','Marker','d','XData',pltx,'YData',plty);
z(Nx3) is a matrix with the coordinates of each point.
Now i would like to plot a line that would follow the order in the matrix routes connecting the points with z coordinates.
The outcome im looking for is this:
or something close. Any ideas on what else i would need to add to my code to make it work ?

采纳的回答

William Rose
William Rose 2022-10-3
N=76; %number of points
z=80*rand(N,3); %point coordinates
routes=[1 5 46 1 0 0 0 0 0 0 0;
1 41 10 40 73 13 27 1 0 0 0;
1 31 75 49 30 16 58 14 28 53 1;
1 68 36 20 55 9 47 35 1 0 0;
1 7 34 24 57 64 1 0 0 0 0;
1 4 45 25 50 17 52 1 0 0 0;
1 59 11 32 26 56 19 51 33 18 1;
1 2 44 42 43 65 23 62 22 29 1;
1 48 37 70 72 61 71 21 38 6 1;
1 76 69 3 63 74 1 0 0 0 0;
1 39 12 66 67 60 15 54 8 1 0];
routes(routes==0)=1; %changes 0s to 1s to make plotting simpler
scatter(z(:,2),z(:,3),'d',"filled"); %plot points
a = num2str([1:N]'); labels=cellstr(a);
text(z(:,2)+1,z(:,3)+1,labels,'fontsize',8); %label each point
hold on;
for i=1:11
plot(z(routes(i,:),2),z(routes(i,:),3))
end
Try it. Good luck.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by