Create a .gif from series of images created in a for loop

5 次查看(过去 30 天)
Hi,
So I have some working code that reads in some data files, does some manipulation on said data and creates an image file based up the results. I can save each image generated into a specified output file, yet I also wish to create a .gif, where each frame is the image that just got generated. The code I currently have seems to just not work, and only uses the 1st image created. My code is below.
Any help would be greately appriciated!
cd('........')
output_file='.......';
gif_name = 'test.gif';
for count = 0:50;
%DATA MANIPULATION
..................
%CREATE AND SAVE IMAGE
data_figure = figure('Visible','off');
axes1 = axes('Parent', data_figure, 'ZGrid', 'on', 'YGrid', 'on');
view(axes1,[0.5 90]);
xlim(axes1,[-0.01 0.25]);
hold(axes1, 'all');
surf(data_A,data_B,data_C, 'Edgecolor', 'none');
colorbar;
xlabel('........');
ylabel('.........');
set(gca, 'XGrid', 'off');
ylabel(colorbar, '.......');
saveas(gcf, fullfile(output_file, [num2str(count),'.png']));
%PART THAT DOESNT WORK....CREATING GIF
frame = getframe(1);
im = frame2im(frame);
[AA,map] = rgb2ind(im,256);
if count == 0,
imwrite(AA,map,gif_name,'gif','LoopCount',Inf,'DelayTime',1);
else
imwrite(AA,map,gif_name,'gif','WriteMode','append','DelayTime',1);
end
end
  1 个评论
David
David 2014-8-15
Ok I have gotten it to work by changing frame = getframe(1); to frame=getframe(data_figure);
yet it diplays each frame on screen as it is creating the file, how do I stop this?

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2014-8-15
getframe() pulls the image out of the axes. If you don't want it to be displayed, then you can't use getframe(). You'll have to create the image yourself somehow.

类别

Help CenterFile Exchange 中查找有关 Display Image 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by