Figure Plot Slow

2 次查看(过去 30 天)
Yonghe
Yonghe 2011-3-4
A Matlab program plots DATA at run time. X axis is time, DATA is an event flag we monitor. If the event happens at time 2ms, then a dot is placed (plotted) at time 2ms. For each trial, we have a sequence of the event that happened at times. Y axis is Trial number. I used ‘hold on’ to plot on the same figure as new trials coming in. The problem is: at the beginning of the plot figure (new figure), the plot goes fast, but as more trials plotted, it becomes really slow. Could someone help me on what the cause could be? How to resolve? Thank you!

采纳的回答

Walter Roberson
Walter Roberson 2011-3-4
Instead of plotting more and more objects on the same plot, it is better to use scatter() and record the handle and then as more data comes in, set() the XData and YData properties of the handle to an array that includes all of the data.
h = scatter(...)
set(h,'XData', [get(h, 'XData'), newxvals], ...
'YData', [get(h, 'YData'), newyvals])
  3 个评论
Walter Roberson
Walter Roberson 2011-3-4
Yes, this will work fine as long as you always add the same number of x and y. The new x and y values will need to be in column vectors for this to work.
Yonghe
Yonghe 2011-3-7
Update after testing:
I noticed that 'plot' runs faster than 'scatter' for my case. I used your suggestion of utilizing handler with 'plot' and the speed improved significantly.
Thank you, Walter, again!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by