Draw Lines between Points in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter EngWiPy
  • Start date Start date
  • Tags Tags
    Lines Matlab Points
Click For Summary

Discussion Overview

The discussion revolves around connecting points represented in a matrix using MATLAB, specifically focusing on both 2D and 3D plotting techniques. Participants explore methods to create closed graphs and connect adjacent points in a polytope.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant inquires about connecting points in a 5-by-2 matrix in MATLAB.
  • Another suggests using the command plot(V(:,1),V(:,2)) to connect the points.
  • A participant reports that the initial suggestion only connects three points and seeks a method to form a closed graph.
  • It is proposed that appending the starting point to the matrix could create a closed graph.
  • One participant confirms that appending the start point resolves their issue.
  • A later post raises the question of extending the solution to 3D plotting.
  • Another participant suggests using plot3() for 3D connections, but notes that it connects all points rather than just adjacent ones.
  • One participant expresses uncertainty about connecting only adjacent vertices in 3D.
  • Another participant suggests breaking the matrix into smaller matrices for plot3() to achieve the desired connections.
  • There is a mention of looking for additional resources on MATLAB's file exchange for potential solutions.

Areas of Agreement / Disagreement

Participants generally agree on the methods for connecting points in 2D, but there is disagreement and uncertainty regarding the approach to connecting only adjacent points in 3D.

Contextual Notes

The discussion includes assumptions about the structure of the matrix and the nature of the polytope, which may affect the proposed solutions. There are also references to external resources that may not be universally applicable.

EngWiPy
Messages
1,361
Reaction score
61
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
 
Physics news on Phys.org
plot(V(:,1),V(:,2)) should do it, if I remember my matrix slicing.
 
jhae2.718 said:
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
 
It only plots three points? :confused:

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.
 
jhae2.718 said:
It only plots three points? :confused:

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.
 
Glad to hear it.
 
jhae2.718 said:
Glad to hear it.

If I want to extend it to 3D, is it straightforward to do that?
 
You should probably be able to do something similar with plot3() for lines in R3.
 
jhae2.718 said:
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?
 
  • #10
S_David said:
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...
 
  • #11
jhae2.718 said:
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
 
  • #12
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/
 
  • #13
jhae2.718 said:
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.
 
  • #14
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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K