Borrar filtros
Borrar filtros

Save a created .gif into defined file location

2 visualizaciones (últimos 30 días)
David
David el 18 de Ag. de 2014
Comentada: Guillaume el 18 de Ag. de 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

Respuesta aceptada

Guillaume
Guillaume el 18 de Ag. de 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 comentarios
David
David el 18 de Ag. de 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 el 18 de Ag. de 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).

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by