Plotting points and lines

8 ビュー (過去 30 日間)
alex
alex 2012 年 4 月 23 日
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 Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by