要回答问题的第一部分,如何显示液滴运动:
如果你可以这样做:
X = rand(10,1)*10;
Y = rand(10,1)*10;
figure
for i = 1:length(X)
plot(X(i),Y(i),'o')
xlim([0,10]) %fix the x and y limit
ylim([0,10]) %fix the x and y limit
F(i) = getframe;
drawnow
end
movie(F)
我们必须修复 x 限制和 y 限制,否则您的点将始终出现在屏幕中间。
如果要保存视频(例如 .avi):
X = rand(10,1)*10;
Y = rand(10,1)*10;
v = VideoWriter('test.avi'); %create a video in your current folder
open(v)
figure
for i = 1:length(X)
plot(X(i),Y(i),'o')
xlim([0,10])
ylim([0,10])
F(i) = getframe;
writeVideo(v,F(i))
end
close(v)
只是为了好玩:
X = 1:100;
Y = 1:100;
Z = 1:100;
v = VideoWriter('test2.avi');
open(v)
[x,y,z] = sphere;
figure
for i = 1:length(X)
surf(x+0.1*X(i),y+0.1*Y(i),z+0.1*Z(i));
xlim([0,10])
ylim([0,10])
zlim([0,10])
view(30,30)
F(i) = getframe;
writeVideo(v,F(i))
end
close(v)
但是这种方法很慢,因为 matlab 必须渲染每一帧。