How to connect multiple points in order using the shortest line
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Romio
el 29 de Abr. de 2021
Respondida: Matt J
el 29 de Abr. de 2021
I have the following discrete points.
The x and y coordinates are the following
X = [-0.5305 -2.0960 -1.6192 -2.2768 -1.9141 -2.0279 -2.0102 -2.0087 -2.0083 -2.0083 -2.0083]
Y = [3.4667 1.7524 1.0045 1.2514 1.0493 1.1818 1.1733 1.1763 1.1762 1.1762 1.1762]
I want to draw lines that connect these coordinates in a consecutive way using the shortest distance among them. For example the first line is between (-0.5305,3.4667) and (-2.0960, 1.7524). The second is between (-2.0960, 1.7524) and (-1.6192,1.0045) and so on.
I tried the following code, but it gave me weird lines that are not the shortest
for i = 1:length(Xk)-1
for j = i+1:length(Xk)-1
plot([Xk(i) Xk(j)],[Yk(i) Yk(i)])
plot([Xk(j) Xk(j)],[Yk(i) Yk(j)])
pause(0.01)
end
end
0 comentarios
Respuesta aceptada
Matt J
el 29 de Abr. de 2021
X = [-0.5305 -2.0960 -1.6192 -2.2768 -1.9141 -2.0279 -2.0102 -2.0087 -2.0083 -2.0083 -2.0083];
Y = [3.4667 1.7524 1.0045 1.2514 1.0493 1.1818 1.1733 1.1763 1.1762 1.1762 1.1762];
line(X,Y)
0 comentarios
Más respuestas (1)
Matt J
el 29 de Abr. de 2021
X = [-0.5305 -2.0960 -1.6192 -2.2768 -1.9141 -2.0279 -2.0102 -2.0087 -2.0083 -2.0083 -2.0083];
Y = [3.4667 1.7524 1.0045 1.2514 1.0493 1.1818 1.1733 1.1763 1.1762 1.1762 1.1762];
p=polyshape(X,Y);
plot(p,'FaceColor','none')
0 comentarios
Ver también
Categorías
Más información sobre Graph and Network Algorithms en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!