add points to plot

조회 수: 6 (최근 30일)
Nuno
Nuno 2011년 3월 4일
I'm using the following code to add points to a plot the fastest way possible. But this way I need to read the existing points, add the news and set them back. Is there a simpler way?
if ishandle(handle_in)
set(handle_in,'XData',[get(handle_in,'XData') posicaoX],'YData',[get(handle_in,'YData') posicaoY]);
handle_out=handle_in;
else handle_out=plot(posicaoX,posicaoY,options,'LineWidth',1,'MarkerSize',10);
end
  댓글 수: 1
Andrew Newell
Andrew Newell 2011년 3월 4일
Could you please format this code so that it is more readable? See http://www.mathworks.com/matlabcentral/answers/help/markup.

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

채택된 답변

Jan
Jan 2011년 3월 4일
Your soultion looks efficient. The distinction between "handle_in" and "handle_out" is not needed and the line "handle_out=handle_in" can be omitted if you use LineH for both (not "handle", because this is used by Matlab already).
One idea would be to create a LINE without data at first, such that the ISHANDLE test is not necessary.
If you update the line very often (>10.000 times), pre-allocation will increase the speed: Initialize the line with the maximal number of elements and set them to Inf. Store the current index for inserting new values e.g. in the UserData of the line.
  댓글 수: 6
Jan
Jan 2011년 3월 4일
Another method to gain speed: The XData and YData are searched at each update for min and max values to update the X- and Y-limits. If you can fix these limits (e.g. 'XLim', [0,10000], 'YLim', [-1, 1]) and set the undocumented properties 'YLimInclude' and 'XLimInclude' of the LINE handle to 'off', Matlab does not search the new min and max.
Jan
Jan 2011년 3월 4일
@Walter: Inf's and NaN's are both not drawn.
@Nuno: If you have fixed size for X-limits and Y-limits, I could summarize the ideas in a new code example.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by