MATLAB Answers

Union Colleg

I made a 2D color plot, how do I turn the plot into an animation or video of the points being put into place? Thanks

Asked by Union Colleg
on 17 Jul 2013
Latest activity Answered by Ricardo A. Baila on 6 Jul 2016

The plots differ in color based on the Z value.




No products are associated with this question.

5 Answers

Answer by Youssef Khmou
on 17 Jul 2013


If you mean you have a plot from 2 vectors x and y, then you can use the function pause to drawn each point :

 for n=1:length(x)
        pause(N),    % where N is numbers of seconds
        hold on,

Here is an example from my File Exchange :


Answer by Union Colleg
on 17 Jul 2013

Thank you very much these have both been very helpful as I am just starting up in the matlab world.


Answer by Shane
on 18 Jul 2013
Edited by Shane
on 18 Jul 2013

The comet function is also quite nice.

    X = sin(0:.01:2*pi);
  X = sin(0:.01:2*pi);
  Y = 0:.01:2*pi;

  1 Comment

Yes, though it could be even better if there were some way to control the speed of the comet and length of the tail.

Answer by Ricardo A. Baila on 6 Jul 2016

You might want to check out:

doc animatedline

Example from the documentation:

Create the initial animated line object. Then, use a loop to add 1,000 points to the line. After adding each new point, use drawnow to display the new point on the screen.

h = animatedline;
x = linspace(0,4*pi,1000);
y = sin(x);
for k = 1:length(x)

(And you can control the drawing speed up to a certain degree by resourcing to the pause command)


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!