Effacer les filtres
Effacer les filtres

Save a created .gif into defined file location

2 vues (au cours des 30 derniers jours)
David
David le 18 Août 2014
Commenté : Guillaume le 18 Août 2014
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

Réponse acceptée

Guillaume
Guillaume le 18 Août 2014
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 commentaires
David
David le 18 Août 2014
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 le 18 Août 2014
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).

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by