Plotting points and lines

8 visualizzazioni (ultimi 30 giorni)
alex
alex il 23 Apr 2012
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];

Risposta accettata

Walter Roberson
Walter Roberson il 23 Apr 2012
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 Commenti
Walter Roberson
Walter Roberson il 25 Apr 2012
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 il 25 Apr 2012
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)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by