问题
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