Why does updating a simple graphics object take more time if there is another graphics object in the same figure with a large number of points in MATLAB?
2 views (last 30 days)
Show older comments
I use the code below to move a red line across a waveform. If I increase tmax from 1e3 to 1e6, it take an extremely long time for the red line to move across the plot. It is gets slower even though the number of times I update the red line is constant.
Changing the renderer does not help. Setting the NextPlot property for the figure and axes to 'add' also does not help.
tmax = 1e3;
t = 1:1:tmax;
%%Frequency Components
f1 = 2000;
f2 = 3500;
f3 = 5000;
f4 = 6500;
f5 = 9000;
%%Input Signal
y = sin(2*pi*f1*t)+...
sin(2*pi*f2*t)+...
sin(2*pi*f3*t)+...
sin(2*pi*f4*t)+...
sin(2*pi*f5*t);
%%Draw the Signal
haxes1 = axes;
set(gcf,...
'Numbertitle', 'off',...
'Name', 'Sound Player',...
'CurrentAxes',haxes1)
plot(t,y)
drawnow;
set(haxes1,'NextPlot','add');
%%Draw the moving line marker.
ind_res = 500;
step = (max(t)-min(t))/ind_res;
axis manual;
htemp = line([1 1], [-1 1], 'Color', 'r');
drawnow;
for ii = step:step:max(t)
set(htemp,'XData',[ii ii]);
drawnow;
end
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
This is expected behavior. As the number of points increases for a graphics objects in the figure, updating another graphics object in the figure will slow down.
One workaround is to set the EraseMode property to 'xor' for the object that is being updated. This should speed the operations up significantly because it operates on pixels instead of coordinates. For example, use the following command to define the red line:
htemp = line([1 1], [-1 1], 'Color', 'r', 'erasemode','xor');
0 Comments
More Answers (0)
See Also
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!