18 views (last 30 days)

Hi all, I want to draw path between points, but the paths cannor be diagonal. Therefore the paths should have corners. Think it as a rectangle, you want to move from a corner to another corner, but cannot move diagonally. How can I show that on matlab? The coordinates are attached.

Thanks

darova
on 29 Dec 2019

I reached a succes

p = xlsread('coordinates');

x = p(:,1);

y = p(:,2);

plot(x,y,'.r')

hold on

for i = 1:length(x)-1

plot([x(i) x(i+1)],[y(i) y(i)])

plot([x(i+1) x(i+1)],[y(i) y(i+1)])

pause(0.5)

end

hold off

darova
on 29 Dec 2019

- While visiting the points in the file 'coordinate' if I the line crosses an obstacle(which is attached as file)

It's too complicated for this forum. You should incorporate your own script

To connect each point with each points use this code:

for i = 1:length(x)-1

for j = i+1:length(x)-1

plot([x(i) x(j)],[y(i) y(i)])

plot([x(j) x(j)],[y(i) y(j)])

pause(0.01)

end

end

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/498369-find-path-between-two-points-with-x-and-y-coordinates#comment_781740

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/498369-find-path-between-two-points-with-x-and-y-coordinates#comment_781740

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/498369-find-path-between-two-points-with-x-and-y-coordinates#comment_781741

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/498369-find-path-between-two-points-with-x-and-y-coordinates#comment_781741

Sign in to comment.