How to create movies on each generation of a for loop in Matlab plot

我是研究僧i 提交于 2019-12-02 09:50:20

To create movie reflecting changes in figures, I am using combination of the class avifile and functions getframe() and addframe()

Here is an example

aviobj = avifile('example.avi','compression','None');

t = linspace(0,2.5*pi,40);
fact = 10*sin(t);
fig=figure;
[x,y,z] = peaks;
for k=1:length(fact)
    h = surf(x,y,fact(k)*z);
    axis([-3 3 -3 3 -80 80])
    axis off
    caxis([-90 90])

    F = getframe(fig);
    aviobj = addframe(aviobj,F);
end
close(fig);
aviobj = close(aviobj);

You can find more info here

http://www.mathworks.nl/help/matlab/ref/avifile.html

http://www.mathworks.nl/help/matlab/ref/movie.html

http://www.math.canterbury.ac.nz/~c.scarrott/MATLAB_Movies/movies.html

-----------------Edit after the discussion in the comments------------------

pm89 suggested another way in the comments. The VideoWriter class seems more modern and up to date. The example of use can be found at the end of the page below

http://www.mathworks.nl/help/matlab/ref/videowriterclass.html

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