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

102 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.
  3 Comments
Naum Derzhi
Naum Derzhi on 29 Nov 2017
Here is a code sample demonstrating what is lost when 'EraseMode','xor' is not available:
h=axes('XLim',[0,2],'YLim',[0,2]); patch([0,1,1,0],[0,0,2,2],'r'); patch([1,2,2,1],[0,0,2,2],'g'); l=line([0,2],[0,2],'EraseMode','xor'); l1=line([0,2],[2,0],'Color','r');
Of course you can run this snippet only in an earlier Matlab version. In this example, the second line, drawn without 'xor', is visible only in one of the patches. When you have to draw a line on top of an arbitrarily colored image, where you are going to cross a variety of colors, XOR is the only way to ensure that the line is visible (almost) everywhere.
I will accept not being able to accurately print figures, but I still need to be able to SHOW the line on top of a raster in interactive session

Sign in to comment.

More Answers (0)

Products


Release

R2014b

Community Treasure Hunt

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

Start Hunting!