Animation help needed with

4 次查看(过去 30 天)
Tom
Tom 2012-1-18
评论: David 2013-10-25
Animation help needed
I'm trying to display 10 graphs in a sequence as an animation, running from t=1 to t=10. Here's my code,
close all;
clear all;
l=0.33;R=100;T=68;m=0.000125;w0=0.1;t=0;mu=m/l;c=sqrt(T/mu);r=1/2;x0=l*r;
for t = 1:10
for x=1:34;
for n=1:5000;
wxt=((4*w0)/pi)*exp(-R*(t*0.001))*((l/(pi*n^2*x0))...
*sin((n*pi*x0)/l))*sin((n*pi*((x-1)*0.01))/l)*cos((sqrt((c*n*pi/l)^2-R^2)*(t*0.001)));
wxtrec(n)=wxt;
end
w=sum(wxtrec);
wrec(x)=w;
end
end
plot(1:34,wrec(t+10))
axis equal
M(t) = getframe
%plot(1:34,wrec)
The bottom plot works by its self, displaying the graph of t=10, but I can't seem to make the animation work.
Any help would be really appreciated.

采纳的回答

Chandra Kurniawan
Chandra Kurniawan 2012-1-18
l =0.33;R=100;T=68;m=0.000125;w0=0.1;t=0;mu=m/l;c=sqrt(T/mu);r=1/2;x0=l*r;
for t = 1:10
for x=1:34;
for n=1:5000;
wxt=((4*w0)/pi)*exp(-R*(t*0.001))*((l/(pi*n^2*x0))...
*sin((n*pi*x0)/l))*sin((n*pi*((x-1)*0.01))/l)*cos((sqrt((c*n*pi/l)^2-R^2)*(t*0.001)));
wxtrec(n)=wxt;
end
w=sum(wxtrec);
wrec(x)=w;
end
plot(1:34,wrec)
M(t) = getframe
end
%plot(1:34,wrec(t+10))
%axis equal
%M(t) = getframe
%plot(1:34,wrec)
movie(M)

更多回答(4 个)

Tom
Tom 2012-1-18
Brilliant! That's really good thank you loads. One last thing - is there a way to stop the vertical axis from automatically changing its scale for each graph? I just tried and all I did was just stop the animation from working.
  1 个评论
Chandra Kurniawan
Chandra Kurniawan 2012-1-18
Hi,
You can write :
axis ([0 35 -0.05 0.05]);
before line
plot(1:34,wrec)
inside the loop.
Or you can also set the axis unvisible inside the loop by
axis off

请先登录,再进行评论。


Tom
Tom 2012-1-18
Actually - it did work I just couldn't see it properly. Many thanks again.

Chandra Kurniawan
Chandra Kurniawan 2012-1-18
l=0.33;R=100;T=68;m=0.000125;w0=0.1;t=0;mu=m/l;c=sqrt(T/mu);r=1/2;x0=l*r;
axis equal
for t = 1:10
for x=1:34;
for n=1:5000;
wxt=((4*w0)/pi)*exp(-R*(t*0.001))*((l/(pi*n^2*x0))...
*sin((n*pi*x0)/l))*sin((n*pi*((x-1)*0.01))/l)*cos((sqrt((c*n*pi/l)^2-R^2)*(t*0.001)));
wxtrec(n)=wxt;
end
w=sum(wxtrec);
wrec(x)=w;
end
plot(1:34,wrec(t+10));
F(t) = getframe;
end
movie(F)

owr
owr 2012-1-18
If you're not actually trying to make a movie, just visualize the animation within MATLAB, I'd highly recommend calling "plot" just once and capturing a handle to the plot object. You can then update this handle's "ydata" property within your loop without repeatedly calling plot. The result is that the animation will be much smoother and you'll be able to zoom, pan, rotate interactively during the animation without everything reseting. Here is a simple example - try rotating, etc. mid animation to see what Im talking about:
x = -1:0.01:1;
y = x.^2;
h = plot(x,y);
axis([-1,1,-1,1]);
for t = 1:500
set(h,'ydata',cos(t/10)*y);
pause(0.1);
end
Good luck!

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by