Question: I am learning matlab myself andI have made an animated plot using matlab;now i want to save it as an video file.can you tell me how to convert my animation into a video file in matlab.Below is my code 

```
x=[1:2];
for i=1:25,
m=randi([3,5]);
n=randi([3,5]);
y=[m n];
bar(x,y)
axis equal                
A(i) = getframe;          
end

```

matlab version 7.8 R2009a

Answer: 
If Matlab's avifile doesn't work (it might have problems with codecs of 64-bit OS), then use mmwrite.
<http://www.mathworks.com/matlabcentral/fileexchange/15881-mmwrite>

It's simple, and it works. I used it to create \*.wmv files simply by: 
`mmwrite(filename, frames);`

Edit: code example

```
% set params
fps = 25;
n_samples = 5 * fps;
filename = 'd:/rand.wmv';
% allocate frames struct
fig = figure;
f = getframe(fig);
mov = struct('frames', repmat(f, n_samples, 1), ...
    'times', (1 : n_samples)' / fps, ...
    'width', size(f.cdata, 2), ...
    'height', size(f.cdata, 1));
% generate frames
for k = 1 : n_samples
    imagesc(rand(100), [0, 1]);
    drawnow;
    mov.frames(k) = getframe(fig);
end
% save (assuming mmwrite.m is in the path)
mmwrite(filename, mov);

```
Have a look at [`VideoWriter`](https://uk.mathworks.com/help/matlab/ref/videowriter.html) or see this [`forum discussion`](https://uk.mathworks.com/matlabcentral/answers/455886-how-to-save-animated-plots#answer_370280)