rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
lin_evol_animate_solution.m
1 function lin_evol_animate_solution(U, grid, options)
2 %function lin_evol_animate_solution(U, grid, params)
3 %
4 % Animation of the solution U from sim_data and saving animation in a file
5 %
6 % Markus Dihlmann 28.06.10
7 %
8 
9 
10 
11 animation_pause = 0.1; % pause after each plot
12 
13 
14 
15 if nargin==2
16  options=[];
17 end
18 
19 
20 if ~isfield(options,'file_name')
21  options.file_name = 'solutionanimation.avi';
22 end
23 
24 
25 if isfield(options,'figureNr')
26  figure(options.figureNr);
27 else
28  figure;
29 end
30 hold on;
31 
32 
33 if isfield(options,'nr_frames')
34  nr_frames = options.nr_frames;
35  if nr_frames<size(U,2)
36  step = floor(size(U,2)/nr_frames);
37 
38  U_new = zeros(size(U,1),nr_frames);
39 
40  for i=1:nr_frames
41  U_new(:,i) = U(:,i*step);
42  end
43 
44  if (nr_frames*step<size(U,2))
45  U_new = [U_new,U(:,end)];
46  end
47  U=U_new;
48  end
49 end
50 
51 
52 mov = avifile(fullfile(rbmatlabtemp,[options.file_name]));
53  mov.Quality = 100;
54  mov = set(mov,'Compression','None');
55  frame_rep = ceil(15*animation_pause);
56 
57 
58  options.shrink_factor=1.0;
59  options.no_lines=1;
60 
61  nt = size(U,2);
62 
63  for t=1:nt
64  plot_element_data(U(:,t),grid,options);
65 
66  F = getframe(gcf);
67  for fr = 1:frame_rep
68  mov = addframe(mov,F);
69  end;
70  end
71 
72  mov = close(mov);