创建电影每个数据生成数据、电影

2023-09-11 23:31:41 作者:煮酒酿情话

我有以下的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.