Question about plotting a long series of lines

조회 수: 6 (최근 30일)
Brian . 2013년 11월 12일
댓글: Doug Hull . 2013년 11월 12일
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!

채택된 답변

Doug Hull
Doug Hull 2013년 11월 12일
>> 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
Doug Hull
Doug Hull 2013년 11월 12일
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...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)


Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by