Question about plotting a long series of lines

4 visualizaciones (últimos 30 días)
Brian
Brian el 12 de Nov. de 2013
Comentada: Doug Hull el 12 de Nov. de 2013
Hello, thanks for reading this,
I want to plot a series of lines, which can range from 10 or so lines to thousands.
The total network is a binary tree, but not every line bifurcates. What I do at the moment is use a for loop, and plot every line separately, but that can take a large amount of time, and it doesn't help when I need to replot the tree in repetition. I was wondering, is there an easy way to vectorize this?
My data is the following: I have a point matrix (a N by 3 matrix, where I have n points, with columns x y and z coordinates), and a face matrix (a M by 2 matrix, where I have M faces, with point indexes 1 and 2). An example can be the following:
pointMx = [0 0 0; 0 5 0; 0 10 5; 0 10 0];
faceMx = [1 4; 4 2; 4 3];
So I have a total of three lines, with one bifurcating into two segments. I can plot this by looping over the number of rows in faceMx and plotting each line individually, but that can take time. Is there a way to vectorize the plotting of these lines?
Thanks for your help!

Respuesta aceptada

Doug Hull
Doug Hull el 12 de Nov. de 2013
>> clf; tic; for i = 1:10000; h(i) = line(rand(1,2), rand(1,2)); end; toc Elapsed time is 0.933154 seconds.
I respect the idea of limiting your overhead by reducing the number of line objects created. However, 0.9 second to make this graph. Is it really worth your effort to make this more efficient?
  2 comentarios
Brian
Brian el 12 de Nov. de 2013
Wow, this is actually a lot faster than what I had previously... is there a reason my plot3 version of the code took longer?
Plotting 10000 lines with plot3 took much longer. 0.9 seconds for 10000 lines isn't bad at all, thanks I will switch over to the line command.
Doug Hull
Doug Hull el 12 de Nov. de 2013
You were likely making 10000, 3-d lines with the heavyweight plot3 command, rather than the much faster primitive. The overhead of a higher level command like plot3 is no big deal unless you are doing it 10k times...

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by