Traversing Through a Vector of Different-sized Cells
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
Let me first explain the code I want to execute. I have a matrix "V" of size (m x 2), where the first column is x values and the second column is y values. I also have a complex vector of different sized cells called "C". This vector contains indices of V, where each row can be of a different length. So, as an example:
V =
20 40
10 20
5 10
30 15
25 35
C =
1 2 3
5 2 3 1
3 4 2 1
1 5
I would like to draw a line between the coordinates in "V" corresponding to the indices in all of the rows of "C".
Therefore, the last row of "C" should look similar to this:
line([V(1,1) V(1,2)], [V(5,1) V(5,2)])
Is there a way to write some general code that fits this method?
If it helps, I am using this principle to draw Voronoi edges. "V" means the location of the vertices (coordinates) and each row in "C" corresponds to every vertex contained in each cell.
Thanks, Ian
0 Commenti
Risposta accettata
Hugo
il 1 Lug 2013
Assuming that
V =[20 40 10 20 5 10 30 15 25 35];
C ={ {1 2 3}; {5 2 3 1}; {3 4 2 1}; {1 5}};
You can use:
line(V([C{i}{:}],1),V([C{i}{:}],2));
to draw any line based on the indexes in each row in C.
5 Commenti
Hugo
il 2 Lug 2013
The index i corresponds to C, so the for loop should go from 1 to the number of rows in C. That way, there should be any error. Notice that in the example you wrote, C has four rows, and thus, if you set the loop to go from 1 to the number of rows in V, then the index i will reach 5, which is greater than the number of rows in C.
The first line of V being infinity does not produce an error in line. So what to do with that line is something you need to decide based on what you want to plot. There's no technical problem with that. Hope this helps.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Voronoi Diagram in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!