フィルターのクリア

Save a created .gif into defined file location

2 ビュー (過去 30 日間)
David
David 2014 年 8 月 18 日
コメント済み: Guillaume 2014 年 8 月 18 日
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 Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by