Plotting points and lines

8 次查看(过去 30 天)
I have two arrays, one with points, and one of members saying which points they wish to connect. Below is the data. So essentially there is supposed to be points at (node_x,node_y). Then I would like to connect those points with 21 members ie size(member_nodes). For example, the first member should connect nodes 2 and 3 which are at points (0,0) and (5,0) respectively. Also if possible, it would be optimal to label what member/node is what on the plot. Thanks in advance, I realize this is a bit complicated.
node_x = [15.0, 0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 5.0, 10.0, 20.0, 25.0].';
node_y = [5.0 , 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, 5.0, 5.0, 5.0].';
member_nodes = [2, 3;
3, 4;
4, 5;
5, 6;
6, 7;
7, 8;
2, 9
3, 9;
3, 10;
4, 10;
4, 1;
5, 1;
1, 6;
6, 11;
11, 7;
7, 12;
12, 8;
9, 10;
10, 1;
1, 11;
11, 12];

采纳的回答

Walter Roberson
Walter Roberson 2012-4-23
x_coords = [node_x(member_nodes), NaN(size(member_nodes,1),1)];
y_coords = [node_y(member_nodes), NaN(size(member_nodes,1),1)];
plot(x_coords(:), y_coords(:))
  8 个评论
Walter Roberson
Walter Roberson 2012-4-25
Sorry I glanced at this at work but didn't see anything obvious. I do not have access to MATLAB from home.
Walter Roberson
Walter Roberson 2012-4-25
alex, it looks like gplot() would help you.
http://www.mathworks.com/help/techdoc/ref/gplot.html
In your case, the adjacency matrix would be
accumarray(member_nodes, 1)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by