# How to generate a mp4 from an animation

48 views (last 30 days)
Gian Carpinelli on 22 May 2018
Answered: KSSV on 22 May 2018
Hi, so currently I am able to produce an animation but I would like to save this animation as an mp4 and im unsure how to do that. The code is:
%Gian Carpinelli - 18/5/18.
%This script finds L-periodic solutions of the Kuramoto-Sivanshinsky
%equation subject to random initial conditions. The script uses spectral
%methods to solve the KS equations in physical space.
close all clear all
set(groot, 'DefaultLineLineWidth', 1, ... 'DefaultAxesLineWidth', 1, ... 'DefaultAxesFontSize', 16, ... 'DefaultTextFontSize', 12, ... 'DefaultTextInterpreter', 'latex', ... 'DefaultLegendInterpreter', 'latex', ... 'DefaultColorbarTickLabelInterpreter', 'latex', ... 'DefaultAxesTickLabelInterpreter','latex');
f = @(x) 0.01*(2*rand(size(x))-1); % this gives random initial conditions for each run
L = 60; % Enter the desired L value here to see the different flow regiemes. alpha = 2*pi/L;
[x, t, u] = solve_ks(6*L, 2^9, alpha, 400, f);
for k = 1:length(t)
plot(x, u(k,:), '-k')
axis([0 2*pi -2 2])
drawnow
end
figure
contourf(x, t, u,'EdgeColor','none')
set(gcf, 'units', 'inches', 'position', [10 10 10 10])
c = colorbar;
xlabel('\$x\$')
ylabel('\$t\$')
ylabel(c,'u(x,t)')
title('Plot of Solutions to Kuramoto-Sivashinsky Equation')
% sets up the problem for the various L values
function [x, t, u] = solve_ks(N, nt, alpha, T, f)
% solve_ks solves Kuramoto-Sivashinsky equation on a
% 2*pi-periodic domain. % % Inputs: % N - number of collocation points.
% nt - number of times for output.
% nu - viscosity.
% T - final time.
% f - function handle specifying IC. % % Outputs:
% t - row vector containing output times.
% x - row vector containing grid points.
% u - matrix containing solution at t(j)
% in row u(j,:).
% Set up grid.
h = 2*pi/N;
x = h*(0:N-1);
ik = 1i*[0:N/2-1 0 -N/2+1:-1]';
k2 = [0:N/2 -N/2+1:-1]'.^2;
k4 = [0:N/2 -N/2+1:-1]'.^4;
t = linspace(0, T, nt);
% Numerical solution in physical space.
[~, u] = ode15s(@KS, t, f(x));
function dudt = KS(t, u)
uh = fft(u);
ux = ifft(ik.*uh, 'symmetric');
uxx = ifft(-k2.*uh, 'symmetric');
uxxxx =ifft(k4.*uh, 'symmetric');
dudt = -alpha*u.*ux-alpha^2*uxx-alpha^4*uxxxx;
end
end

KSSV on 22 May 2018