How do you draw a line between points in Matlab?

I am looking to create a β€œnetwork” between a set of points where the data indicates whether there is a connection between any two points.

What I thought would be to talk each pair of glasses and lay each pair on top of each other.

However, if there is a way to simply draw a line between two points, it will be much easier.

Any help would be appreciated!

+6
matplotlib graph matlab plot
source share
6 answers

If you can arrange the x and y coordinates of your line segments into 2-on-N arrays, you can use the PLOT function to construct each column of matrices as a row. Here is a simple example for drawing four lines of a unit square:

x = [0 1 1 0; ... 1 1 0 0]; y = [0 0 1 1; ... 0 1 1 0]; plot(x,y); 

This will display each line in a different color. To display all lines as black, do the following:

 plot(x,y,'k'); 
+9
source share

Use plot . Suppose your two points are: a = [x1 y1] and b = [x2 y2] , then:

 plot([x1 x2],[y1 y2]); 
+7
source share

If you meant I'm looking to create a "web" between a set of points where the data tells whether there is a link between any two points there is actually some kind of graph represented by its adjacency matrix (opposite to other simple answers to connect the points), then:

This gplot feature may indeed be the right tool for you. This is the main visualization tool for building nodes and links a graph , presented in the form of an adjacency matrix.

+2
source share

use this function:

 function [] = drawline(p1, p2 ,color) %enter code here theta = atan2( p2(2) - p1(2), p2(1) - p1(1)); r = sqrt( (p2(1) - p1(1))^2 + (p2(2) - p1(2))^2); line = 0:0.01: r; x = p1(1) + line*cos(theta); y = p1(2) + line*sin(theta); plot(x, y , color) 

name it like this:

 drawline([fx(i) fy(i)] ,[y(i,1) y(i,2)],'red') 

Credit: http://www.mathworks.com/matlabcentral/answers/108652-draw-lines-between-points#answer_139175

+2
source share

Suppose you need a line with coordinates (x1, y1) and (x2, y2). Then you create a vector with x and y coordinates: x = [x1 x2] and y = [y1 y2] . Matlab has a Line function, which is used as follows: lines (x, y)

+1
source share

If you want to see the effect of line drawing, you can use plot inside the for tag, that data is a * 2 matrix containing "x, y" of "n" points

 clf(figure(3)) for i = 1 : length(data)-1 plot([data(i,1),data(i+1,1)], [data(i,2),data(i+1,2)], '-*'); hold on end hold off 

Or you can use this operator to draw it in one step.

 plot(data(:,1), data(:,2), '-*'); 
0
source share

All Articles