MATLAB A simple plot animation in Matlab

AI Thread Summary
A user seeks assistance with plotting the function y(x,t) = sin(x) * e^(-t) in MATLAB, specifically wanting to create an animation that shows the sine wave's amplitude decreasing over time. They express frustration with existing animation demos, finding them overly complex. Initial attempts to plot the function result in error messages, leading to confusion about the correct syntax and functions to use. After several trials, they share a working code snippet that animates the sine wave but describe the output as "ugly" and seek suggestions for improvement. Another user joins the conversation, asking about animating a series of vectors that change over time, indicating a broader interest in dynamic plotting in MATLAB. The discussion highlights challenges faced by beginners in MATLAB and the need for clearer examples and guidance for creating effective animations.
Ahmes
Messages
75
Reaction score
1
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.

Thanks in advance.
 
Physics news on Phys.org
something like plot(sin(x)*e^(-t),([x, xstart, xend],[t, tstart, tend]))
 
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.
 
Ok try again
plot3d(y+sin(x)*e^(-t),([y, ystart, yend],[x, xstart, xend],[t, tstart, tend]));
 
Last edited:
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:
YES! I think I've done it!
But it's awfully ugly does anybody know a better way to do it?

Code:
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.
 
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..
 

Similar threads

Replies
8
Views
2K
Replies
2
Views
2K
Replies
4
Views
2K
Replies
1
Views
2K
Replies
2
Views
3K
Replies
1
Views
3K
Back
Top