创建电影每个数据生成 [英] Creating Movie for each Generation of Data

查看:358
本文介绍了创建电影每个数据生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

figure;
contour(X1,X2,f);

hold on

plot(top(1:size(top,1)), 'rx');

修改

EDIT

    figure;
for i = 1: G
    contour(X1,X2,f);

    hold on

    plot(top(1:size(top,1)), 'rx');
end

注意:G为最大的生成。 这是应该绘制球体叠加选择的个体的轮廓。在个人的每次迭代中,最好的个体被选择并且这些事情,直到全局最优为止。我要在电影的形式显示这是显示在此如下:

NB: G is the maximum generation. This is supposed to plot contours of sphere superimposed with selected individuals. In each iteration of the individuals, the best individuals is selected and these going on until the global optimum is reached. I need to show this in a movie form as shown in this below:

在运行迭代的每个阶段显示在附连的幻灯片。这就是我要做的。任何想法吗?

When you runs each stage of the iteration is indicated in the slides attached. This is what i am trying to do. Any idea please?

推荐答案

OK,我只是复制和粘贴现在,从的此处。 不过,我加入帧率(每秒),因为你可能需要使用(或要求),它以后。

OK, I am just copying and pasting now, from here. However I added FrameRate (per second) since you might want to use (or ask) it later.

writerObj = VideoWriter('Your_video.avi');
writerObj .FrameRate = 1; % 1 frames per second animation.
open(writerObj);

fig_h = figure;
for i = 1: G
    contour(X1,X2,f);
    hold on
    plot(top(1:size(top,1)), 'rx');

    frame = getframe(fig_h); % or frame = getframe; since getframe gets gcf.
    writeVideo(writerObj, frame);
end

close(writerObj);

现在你将有一个 Your_video.avi 文件在工作目录。

Now you will have a Your_video.avi file in your working directory.

如果 VideoWriter 不支持您的MATLAB,您可以使用使用 avifile 一样提到这个回答(或mathwork文件建立例如< A HREF =htt​​p://www.mathworks.com/help/matlab/ref/avifile.html相对=nofollow>这里)是这样的:

If VideoWriter is not supported by your matlab, you could use use avifile same as mentioned in this answer (or in mathwork documentaion example here) like this:

aviobj = avifile('Your_video.avi','compression','None', 'fps', 1);

fig_h = figure;
for i = 1:G
    contour(X1,X2,f);
    hold on
    plot(top(1:size(top,1)), 'rx');

    frame = getframe(fig_h); % or frame = getframe; since getframe gets gcf.
    aviobj = addframe(aviobj, frame);
end

aviobj = close(aviobj);


修改

正如刚才这个问题还,这是捕获的帧是一个固定的图像,可能会发生问题。如果你在Windows上运行MATLAB,这个问题可以通过窗口一起与某些显卡驱动程序引起的,如提及可能会解决这个答案

A problem may occur as pointed out by this question also, which is the captured frame is a constant image. If you are running Matlab on windows, this problem may be caused by conjunction of windows in with certain graphics drivers, and may be solved as mentioned in this answer.

这篇关于创建电影每个数据生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆