Animation help needed with

1 回表示 (過去 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!
  1 件のコメント
David
David 2013 年 10 月 25 日
Thanks for sharing this!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by