Matlab基础学习(5)

动画的制作。

Matlab制作简单的动画,主要有三种方法:
1.运动轨迹:comet(),comet3(),ezplot3()
2.影片模式:getframe(),movie()
3.擦除模式:
 
1.运动模式
一个质点的运动动画。
主要有以下三个函数:
comet(x,y)
comet3(x,y,z)
ezplot3(...,'animate')
具体见help
 
2.影片模式
使用getframe()和movie()两个函数
getframe()进行帧抓取
movie()播放动画
 
getframe() %抓取当前的axes(gca)
getframe(h) %抓取axes或figure对象
 
getframe returns a movie frame, which is a structure having two fields:
cdata — The image data stored as a matrix of uint8 values. The dimensions of F.cdata are height-by-width-by-3.
colormap — The colormap stored as an n-by-3 matrix of doubles. F.colormap is empty on true color systems.
 
 
movie(M) %M是getframe()返回的矩阵
movie(M,n) %播放n次
movie(M,n,fps) %每秒fps帧(frame per second)
 
因为getframe()需要抓取一系列的帧,所以一般配合循环。
 
Z = peaks;
figure('Renderer','zbuffer');
surf(Z);
axis tight;
set(gca,'NextPlot','replaceChildren');
for j = 1:20
    surf(sin(2*pi*j/20)*Z,Z)
    F(j) = getframe;
end
movie(F,20) % Play the movie twenty times
 
3.擦除模式
drawnow; %绘制
line('erasemode','模式')
xor和normal如同运动轨迹,normal效果更好,速度慢;xor速度快,效果差于normal
backgrund橡皮的效果
none留下痕迹的轨迹
 
同样使用一个循环,每次循环进行一次drawnow figure(1);
 x=0:pi/50:2*pi;
 y=sin(x);
 plot(x,y);
h=line(0,0,'color','r','markersize',40,'erasemode','none','marker','.');
 axesvalue=axis;
 for j=1:length(x)
set(h,'xdata',x(j),'ydata',y(j),'color','r'); %改变xdata和ydata
axis(axesvalue);
drawnow;
pause(.2);
end

 

posted @ 2015-12-10 18:31  霖霖柒  阅读(227)  评论(0)    收藏  举报