# A simple plot animation in Matlab

1. Feb 14, 2006

### Ahmes

Hi,
Can anyone plesae help me plot $y(x,t)=\sin(x)\cdot e^{-t}$ on an XY axes system, and have the graph to propagate in time?

I'm really new to Matlab, and the animation demos I found were too fancy, and I couldn't figure out how to do what I want.

2. Feb 14, 2006

### Dumbobaby

something like plot(sin(x)*e^(-t),([x, xstart, xend],[t, tstart, tend]))

3. Feb 14, 2006

### Ahmes

I think that plot will just draw the implicit function $f(x,t)=0$.
As I said I'm really new, I tried to type what you said and it gave a bunch of error messages. I tried to create vectors x and t, when it didn't work I tried symbolic variables x and t, replace e with exp(), remove some brackets... still couldn't do it.

4. Feb 14, 2006

### Dumbobaby

Ok try again
plot3d(y+sin(x)*e^(-t),([y, ystart, yend],[x, xstart, xend],[t, tstart, tend]));

Last edited: Feb 14, 2006
5. Feb 14, 2006

### Ahmes

Are you sure about that?
First I didn't see any "plot3d"... there's just the "plot3" and "surf" - The only reference I saw between plot3 and animation is that it can draw a curve from parameterization, and animate a ball traveling on the curve (taking the parameter as time) - this is NOT what I need.
As I said, I would like to see a sine wave $y=\sin(x)$ whose amplitude decreases exponentially ON TIME when I push a "Play" button or something.

Last edited: Feb 14, 2006
6. Feb 14, 2006

### Ahmes

YES! I think I've done it!
But it's awfully ugly :yuck: does anybody know a better way to do it?

Code (Text):

function doit
x=-5:.2:5;
y=sin(x);
h=plot(x,y);
axis([-2*pi 2*pi -1 1])
axis square
grid off
set(h,'EraseMode','xor','MarkerSize',18)
for t=2:.1:7
drawnow
y=sin(x)*exp(-t);
set(h,'YData',y)
pause(0.05)
end

I constructed it from a demo.

7. Jul 8, 2008

### shidao

Hi guys

I have a similar doubt, I have an animation plot with vectors.

I have the following vector A, for example, A at time zero = [23 25 32 21 43], A in the time 1 = [32 22 33 12 42], and so on, several vectors changing their values over time.

It is possible to animate the plot in matlab?

Someone could help?

Thanks a lot guys..