I was wondering if anyone knew how to do an animation plot of x = (dataset of 1000 points) y = (dataset of 1000 points) plot(x,y)
big problem is these are datasets that i am trying to plot , or x,y coordinates as opposed to a function which I would know how to plot via an animation.
I tried to do frames in a for loop but it gave me dots and didn't join them in a line graph so I couldn't really watch the path being traced out.
code I used was
for i = 1:length(DATASET1)
pause(0.1)
plot(DATASET1(i),DATASET2(i))
draw on
end
Since R2014b, you can work with
annimatedline
object (doc and how-to) that is meant to handle animated graphs pretty well. Basically, theannimatedline
object has aaddpoints
function that adds new points to the line without having to redefine the existing points, along with aclearpoints
function that clears lines for more complex animations.Here is an example:
Looks like you were close. Not sure
draw on
is any command though.See if the code here inspires you to solve your case -
If what you want is for the plot to "grow" point by point: the easiest way is to create an empty plot and then update its
XData
andYData
properties at each iteration:Here's an example1 obtained with
DATASET1 = 1:100; DATASET2 = sin((1:100)/6);
1 In case someone's interested, the figure is an animated gif which can be created by adding the following code (taken from here) within the loop, after the
drawnow
line: