Animation help needed with
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tom
el 18 de En. de 2012
Comentada: David
el 25 de Oct. de 2013
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.
0 comentarios
Respuesta aceptada
Chandra Kurniawan
el 18 de En. de 2012
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)
0 comentarios
Más respuestas (4)
Tom
el 18 de En. de 2012
1 comentario
Chandra Kurniawan
el 18 de En. de 2012
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
Chandra Kurniawan
el 18 de En. de 2012
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)
0 comentarios
owr
el 18 de En. de 2012
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!
Ver también
Categorías
Más información sobre Animation en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!