-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_gif.m
56 lines (45 loc) · 1.54 KB
/
make_gif.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function [] = make_gif( M_for_gif,output_file,speed,max_color_scale )
[~,~,st]=size(M_for_gif);
for ep_to_plot=1:st
display(strcat('create gif, step:',num2str(ep_to_plot),'/',num2str(st)))
h = figure(4);
set(gcf,'Visible', 'off');
g=subplot(2,1,1);
imagesc(M_for_gif(:,:,ep_to_plot));
title('Map of rain rate (mm/h)')
%axis square
axis equal tight
caxis([0 max_color_scale])
my_map=colormap('jet');
my_map(1,:)=[1 1 1];
colormap(my_map)
set(gca,'XTickLabel',[]);
set(gca,'YTickLabel',[]);
colorbar
p = get(g,'position');
%set(g, 'position', p.*[-0.4 0.8 1.5 1.5]);
set(g, 'position', p.*[-0.4 0.8 1.5 1.2]);
g2=subplot(2,1,2);
plot(reshape(mean(mean(M_for_gif)),[1,st]),'k')
hold on
plot(ep_to_plot,mean(mean(M_for_gif(:,:,ep_to_plot))),'r.','MarkerSize',10)
title('Time series of rain rate averaged over the area of interest')
xlabel('Time (min)') % x-axis label
ylabel('Rain rate (mm/h)') % x-axis label
p2 = get(g2,'position');
set(g2, 'position', p2.*[1 1 1 0.8]);
drawnow;
%capture the plot as an image
frame = getframe(h);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
% Write to the GIF File
if ep_to_plot == 1
imwrite(imind,cm,output_file,'gif', 'Loopcount',inf);
else
gif_fps = speed;
imwrite(imind,cm,output_file,'gif','WriteMode','append','DelayTime',1/gif_fps);
end
close 4
end
end