Save a created .gif into defined file location

2 次查看(过去 30 天)
Hi,
So I have some code that runs though some saved data, processes it, and creates a gif, as shown below;
OUTPUT_FILE
for count = 1:50;
%various code for loading and processing data
......
......
......
......
%create figures for each file
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;
title('......');
xlabel('......');
ylabel('......');
set(gca, 'XGrid', 'off');
ylabel(colorbar, '.....');
%save images in OUTPUT_FILE
saveas(gcf, fullfile(OUTPUT_FILE, [num2str(count),'.png']));
%create gif
drawnow;
frame = getframe(data_figure);
im = frame2im(frame);
[AA,map] = rgb2ind(im,256);
if count == 1,
imwrite(AA,map,gif_name,'gif','LoopCount',Inf,'DelayTime',0.5);
else
imwrite(AA,map,gif_name,'gif','WriteMode','append','DelayTime',0.5);
end
end
How do I set it to save the gif into the OUTPUT_FILE location, as I have done with the individual images?
Thanks

采纳的回答

Guillaume
Guillaume 2014-8-18
Assuming that OUTPUT_FILE contains the full path of the file, and gif_name is just a filename,
path = fileparts(OUTPUT_FILE);
gif_name = fullfile(path, gif_name);
If gif_name also contains a path that you want to discard:
[~, gif_filename, gif_extension] = fileparts(gif_name);
gif_name = fullfile(path, [gif_filename '.' gif_extension]);
  2 个评论
David
David 2014-8-18
didn't work when i used the path variable, yet worked putting the gif_name and output_file variable directly into fullfile. thanks!
Guillaume
Guillaume 2014-8-18
Well, this assumed that OUTPUT_FILE was actually path + file name prefix of the png files you write. If it's just a path, then fileparts is wrong (and you should rename the variable to OUTPUT_PATH).

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by