1
votes

I'm trying to dynamically add information to a 3D plot:

A = [ -8/3 0 0; 0 -10 10; 0 28 -1 ];
y = [35 -10 -7]';
h = 0.01;
p = plot3(y(1),y(2),y(3),'.','EraseMode','none','MarkerSize',2);
axis([0 50 -25 25 -25 25])
hold on
while 1
    A(1,3) = y(2);
    A(3,1) = -y(2);
    ydot = A*y;
    y = y + h*ydot;
    set(p,'XData',y(1),'YData',y(2),'ZData',y(3))
    drawnow
end

I get the following errors:

Warning: The EraseMode property is no longer supported and will error in a future release.

In strange_attractor (line 4) Warning: The EraseMode property is no longer supported and will error in a future release.

In strange_attractor (line 4) Error using matlab.graphics.chart.primitive.Line/set Invalid or deleted object.

Error in strange_attractor (line 12) set(p,'XData',y(1),'YData',y(2),'ZData',y(3))

I understand that I'm using the outdated syntax for dynamically updating the plot that is no longer supported. How do I make it work?

Note that I don't want to call plot3 inside the loop, because it makes the graphing slow and consumes a lot of memory. I hope to call plot3 once and just add new points to the existing plot inside the loop. Can it be done in the new version?

Matlab version: R2018a

1
Please see the documentation - Sardar Usama
When you want to dynamically add information, do you intend to keep the previously plotted values as well? - Sardar Usama
You want to replace your plot3 usage outside your loop with plot3(y(1),y(2),y(3),'.','MarkerSize',2); and replace set(.....): with this plot3(y(1),y(2),y(3),'.', 'MarkerSize',2); ? - Sardar Usama
How do you expect an infinite loop with no breaking condition to not take up all the memory? - Sardar Usama
You've got a good answer below, but you can also just remove the 'EraseMode','none' bit from the plot3 call and everything should work as before. It is only a warning after all... The error message happened only after you closed the window, didn't it? - Cris Luengo

1 Answers

3
votes

In your comment above, when you say "This does not work", what do you mean? A direct modification of your code according to the given link to the documentation works as expected:

A = [ -8/3 0 0; 0 -10 10; 0 28 -1 ];
y = [35 -10 -7]';
h = 0.01;
p = animatedline(y(1),y(2),y(3),'Marker','.','MarkerSize',2);
axis([0 50 -25 25 -25 25])
hold on
while 1
    A(1,3) = y(2);
    A(3,1) = -y(2);
    ydot = A*y;
    y = y + h*ydot;
    addpoints(p,y(1),y(2),y(3))
    drawnow
end

enter image description here