A simple plot animation in Matlab

Click For Summary

Discussion Overview

The discussion revolves around creating a simple animation of a mathematical function in Matlab, specifically the function y(x,t)=sin(x)·e^(-t). Participants seek assistance in plotting this function over time and animating its propagation on an XY axes system.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant requests help with plotting the function and animating it, expressing difficulty with existing demos.
  • Another participant suggests a plotting command that may not align with the intended animation.
  • A different participant raises concerns that the suggested command would only draw an implicit function and shares their struggles with Matlab syntax and errors.
  • Another suggestion involves using a "plot3d" command, which is questioned by a participant who points out the correct commands are "plot3" and "surf".
  • One participant clarifies their goal of visualizing a sine wave whose amplitude decreases over time and seeks a more suitable animation method.
  • A participant shares their code for animating the sine wave, expressing satisfaction with the functionality but dissatisfaction with the aesthetics.
  • Another participant introduces a related question about animating a plot with changing vector values over time, seeking guidance on how to achieve this in Matlab.

Areas of Agreement / Disagreement

Participants express differing opinions on the appropriate commands and methods for achieving the desired animation, and there is no consensus on a single solution. The discussion remains unresolved regarding the best approach to animate the function.

Contextual Notes

Some participants mention specific Matlab commands and syntax, but there are unresolved issues regarding the correct usage and functionality of these commands. Additionally, the aesthetic quality of the animation is noted as a concern by one participant.

Who May Find This Useful

Individuals new to Matlab who are interested in plotting and animating mathematical functions, as well as those looking for solutions to similar animation challenges in data visualization.

Ahmes
Messages
75
Reaction score
1
Hi,
Can anyone plesae help me plot [itex]y(x,t)=\sin(x)\cdot e^{-t}[/itex] 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 [itex]f(x,t)=0[/itex].
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 [itex]y=\sin(x)[/itex] 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 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 11 ·
Replies
11
Views
5K