clear all, close all, clc
load VORTALL;
% VORTALL contains flow fields reshaped into column vectors
X = VORTALL;
r = 21;
[m,n] = size(X);
[Phi, Lambda, b] = DMD(X(:,1:end-1),X(:,2:end),r);

% We will compare data with DMD solutions
L = 0;
Y = zeros(m,n+L);     % initialize DMD solution
for k=1:(n+L)
    for j=1:r
        Y(:,k) = Y(:,k) + b(j)*Lambda(j,j)^(k-1)*Phi(:,j);
    end
end





% Generate video for DMD solutions
% open the videowriter object
v = VideoWriter('cylinderDMD','MPEG-4');
open(v);

% set up the axes
tmp = reshape(Y(:,1),199,449);
imagesc(real(tmp)), colormap jet;
axis tight manual
set(gca,'NextPlot','replacechildren')

% capture all the animation frames
for k = 1:(n+L)
    tmp = reshape(Y(:,k),199,449);
    imagesc(real(tmp)), colormap jet;
    frame = getframe(gcf);
    writeVideo(v,frame);
end

% close the writer
close(v);
