# Draw Lines between Points in MATLAB

by S_David
Tags: draw, lines, matlab, points
 P: 600 Hi, I have a matrix V, which is a 5-by-2 matrix, where each row represents a point in the xy-plain. How can I connect these points together in MATLAB, please? Thanks in advance
 PF Gold P: 1,160 plot(V(:,1),V(:,2)) should do it, if I remember my matrix slicing.
P: 600
 Quote by jhae2.718 plot(V(:,1),V(:,2)) should do it, if I remember my matrix slicing.
Ya, I tried this, but it does not work. It connects just between three points. I need to connect between all points to form a closed graph, starting from a point and ending at the same point.

Thanks

 PF Gold P: 1,160 Draw Lines between Points in MATLAB It only plots three points? I think you should be able to get a connected graph by appending the start point onto the matrix (getting a 6x2) and then using plot.
P: 600
 Quote by jhae2.718 It only plots three points? I think you should be able to get a connected graph by appending the start point onto the matrix (getting a 6x2) and then using plot.
Thank you very much. It is now working perfectly.
 PF Gold P: 1,160 Glad to hear it.
P: 600
 Quote by jhae2.718 Glad to hear it.
If I want to extend it to 3D, is it straightforward to do that?
 PF Gold P: 1,160 You should probably be able to do something similar with plot3() for lines in R3.
P: 600
 Quote by jhae2.718 You should probably be able to do something similar with plot3() for lines in R3.
That indeed works, but this connects all the points together. Actually, in 3D I just want to connect the adjacent points only. How can I do that?
PF Gold
P: 1,160
 Quote by S_David That indeed works, but this connects all the points together. Actually, in 3D I just want to connect the adjacent points only. How can I do that?
I'm not sure what exactly you mean by this...
P: 600
 Quote by jhae2.718 I'm not sure what exactly you mean by this...
Neither do I. But basically, V is a matrix that contains the vertices of a polytope, and I want just to connect the adjacent vertices not all together. I am not sure how to know what are the adjacent vertices from V.

Thanks
 PF Gold P: 1,160 You may have to break the matrix up into matrices such that plot3 will produce the lines connected the way you want. Another option is to look on the file exchange and see if there's anything you can use there. http://www.mathworks.com/matlabcentral/fileexchange/
P: 600
 Quote by jhae2.718 You may have to break the matrix up into matrices such that plot3 will produce the lines connected the way you want. Another option is to look on the file exchange and see if there's anything you can use there. http://www.mathworks.com/matlabcentral/fileexchange/
Ok, I will. Thank you.
 PF Gold P: 1,160 I think there may be a file on the exchange that will do what you want, otherwise I'm afraid I don't know of a built in function that will do what you want on only one call.

 Related Discussions Math & Science Software 2 Calculus & Beyond Homework 10 Math & Science Software 1 Introductory Physics Homework 1 General Math 2