How to animate this 3D plot in Matlab?

 ̄綄美尐妖づ 提交于 2019-12-25 03:52:00

问题


My current code :

a=7
f=10
T=1/f;
v=40
wl=v/f;
x1=1;
x2=30
step=0.01

t=x1:step:x2;
x=x1:step:x2;
y=a*sind(2*pi*f*(t+(x*T)/wl)); 
h=plot3(x,y,t);
set(h,'EraseMode','xor','MarkerSize',20)
xlabel('displacement(m)');
ylabel('amplitude(m)');
title('Wave Animation');
for t=x1:step:x2
drawnow
y=a*sind(2*pi*f*(t+(x*T)/wl)); 
set(h,'YData',y)
pause(0.01)
end

I converted it to a 3D mesh plot but it takes ages to render in animation and Matlab crashes.

a=7
f=10
T=1/f;
v=40
wl=v/f;
x1=1;
x2=30
step=0.01

t=x1:step:x2;
x=x1:step:x2;
[x,t] = meshgrid(x,t);
y     = a*sind(2*pi*f*(t+(x*T)/wl)); 
mesh(y)

What's the best way to animate this so that it looks similar to what I have before making it 3D ?


回答1:


If you can't animate this in real time, an easy alternative is using getframe and movie. You use getframe to capture frames at whatever rate you can generate them, then use movie to replay the frames at a faster frame rate. See the getframe link for a simple example.



来源:https://stackoverflow.com/questions/16426378/how-to-animate-this-3d-plot-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!