How do I replace the 'EraseMode' property in MATLAB R2014b?

95 views (last 30 days)
In MATLAB R2014a and earlier versions, I could animate my plots using the 'EraseMode' property. I noticed that the property does not exist in MATLAB R2014b. How do I replace the 'EraseMode' property?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 2 Aug 2016
Starting in R2014b, the 'EraseMode' property has been removed from all graphics objects. You can still achieve most of the effects produced by 'EraseMode', such as creating animations or producing overlaid colors, using the techniques described here.
To accumulate a picture by adding data to each frame, use one of these approaches instead of setting the EraseMode property to 'none':
  • Use 'hold on' to retain the current data and add new data to the graph.
  •  Use the new 'animatedline' function to create line animations.
  • Use the 'movie' function to play recorded movie frames.
For example, create a line animation using the new 'animatedline' function.
 
theta = linspace(0,2*pi,10000);
h = animatedline();
axis([0,2*pi,-1,1])
 
for t = theta
    addpoints(h,t,sin(t));
    drawnow update;
end
For more information on creating line animations, refer to the documentation for animatedline
To immediately display changes to object data, call 'drawnow update' or 'drawnow expose' instead of setting EraseMode to 'xor'.
  • 'drawnow update' updates a graph with maximum loop speed, but only sends updates if the renderer is free. If the renderer is busy, then 'drawnow update' discards the updates.
  • 'drawnow expose' updates a graph as quickly as possible without losing any updates.
For more information, refer to the documentation for drawnow.
For example, change the 'YData' for a line and display the updates.
 
t = linspace(0,2*pi,10000);
y = exp(sin(t));
h = plot(t,y);
for k = 1:0.01:10
   y = exp(sin(t.*k));
   h.YData = y;
   drawnow expose
end
 
To produce overlaid colors, use transparency instead of setting Erasemode to 'xor'.
 
p1 = patch([0,2,2,0],[0,0,2,2],[1,1,1,1]);
p2 = patch([1,3,3,1],[1,1,3,3],[2,2,2,2]);
p2.FaceAlpha = 0.5;
In R2014a and earlier, setting the 'EraseMode' property to 'xor' increases the rendering speed. Remove code that sets the 'EraseMode' property to get similar rendering speeds.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2014b

Community Treasure Hunt

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

Start Hunting!