To talk on Icrontic, just register!

It only takes 30 seconds.

Have an account? Sign in:

Forgot?
Moly
Getting settled in
Moly
6 Posts

Matlab animation - how to from figures

Compared to the questions out there, my question seems VERY SIMPLE.

I have a code that generates a few graphs. Instead of super-imposing the graphs on one figure, I would like matlab to generate an animation of those graphs for me. I tried looking at help and my intution tells me that getframe is the way to go, but my technical capablities do not extend that far.

Any suggestion on how i can animate these figures? Here is my code

Code:
x0=0; xt=30; dt=.1;
L=(xt-x0)/dt+1;
n=10; 

for k=1:6
      t=5*k; 
      for i=1:L 
           summ=0;
           x(i)=x0+(i-1)*dt;
           for j=1:n 
                npi=j*pi; 
                a=2*(1-cos(npi))-npi^2*(1+cos(npi)); 
                b= exp((-npi^2*t)/900);
                c=sin(npi*x(i)/30);
                summ=summ+((a-b)/j^3)*b*c;
           end
           u(i)=30-x(i)+(60/pi^3)*summ;
      end
      plot(x,u); hold on
end
title(' u(x,t) vs x for several values of t')
shwaip
elaborate bot
shwaip
5,730 Posts
do you want this to display in matlab, or with an external program?
__________________ my photostream for ic photography challenge

Anyone who wants dropbox, please use my referral link
Moly
Getting settled in
Moly
6 Posts
both if possible.
shwaip
elaborate bot
shwaip
5,730 Posts
Code:
x0=0; xt=30; dt=.1;
L=(xt-x0)/dt+1;
n=10; 


figure(1)
for k=1:6
      t=5*k; 
      for i=1:L 
           summ=0;
           x(i)=x0+(i-1)*dt;
           for j=1:n 
                npi=j*pi; 
                a=2*(1-cos(npi))-npi^2*(1+cos(npi)); 
                b= exp((-npi^2*t)/900);
                c=sin(npi*x(i)/30);
                summ=summ+((a-b)/j^3)*b*c;
           end
           u(i)=30-x(i)+(60/pi^3)*summ;
      end
      plot(x,u);
      title(sprintf('u(x,%d)',t));
      m(k)=getframe();
end
movie(m)
movie2avi(m,'movieout.avi','compression','none');
to play the movie in matlab, type: movie(m,# of times you want to repeat)

this also creates a movieout.avi file in the directory you run it in. you may need to tweak the args in movie2avi to make it look like you want
Moly
Getting settled in
Moly
6 Posts
thank you so much for creating the movie.
can i control how long the frame is displayed so that i can see the transition a little slower?
Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch-processing in MATLAB geodave Matlab Help 6 18 Jul 2008 12:58am
Writing new files from Matlab raulinhoo Matlab Help 6 5 Jun 2008 8:31pm
Closing external programs in matlab raulinhoo Matlab Help 2 4 Jun 2008 3:55pm
Matlab 3D figure Amerasu Web & Digital Media 1 21 Jan 2005 4:49pm

Go Back   Icrontic Forums > Tech: Software > General Software > Matlab Help
Jump to
This Thread Search this Thread
Search this Thread:

Advanced Search


Current time: 9:43pm (GMT)
Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Get Vanilla instead. Trust me.