add points to plot
6 次查看(过去 30 天)
显示 更早的评论
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
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
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
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
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 Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!