-
Notifications
You must be signed in to change notification settings - Fork 9
/
make_gifs.m
48 lines (38 loc) · 1.07 KB
/
make_gifs.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
% Single plot
close all
clear all
filename = 'animation2';
dt = 1; % Pause between each frame
F = struct('cdata',[],'colormap',[]);
fh = figure('units','pixels','position',[100 100 1092 384]);
set(gcf,'color','w');
%hold all % If you want to overlap plots
n = 10;
data1 = rand(100,n); % Use your data here
cont = 1;
for i = 1 : n
plot(data1(:,i),'bo')
axis([0,100,0,1])
ax = gca;
ax.Units = 'pixels';
pos = ax.Position;
marg = 30;
rect = [-marg, -marg, pos(3)+2*marg, pos(4)+2*marg];
F(cont) = getframe(ax, rect);
% Pass axis instead of figure to getframe in order to capture only the
% inside of the plot. The margin can be used to get also axes ticks.
[X, map] = rgb2ind(frame2im(F(cont)),256);
cont = cont + 1;
% Write gif
if i == 1
imwrite(X, map, [filename '.gif'], 'Loopcount', inf, 'DelayTime', dt)
else
imwrite(X, map, [filename '.gif'], 'WriteMode', 'Append', 'DelayTime', dt)
end
end
% Write video
v = VideoWriter(filename, 'MPEG-4');
v.FrameRate = 1/dt;
open(v)
writeVideo(v,F)
close(v)