Plotting points and lines

조회 수: 7 (최근 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 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