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: 
use avifile:

```
aviobj = avifile('example.avi','compression','None');
x=[1:2];
for i=1:25,
m=randi([3,5]);
n=randi([3,5]);
y=[m n];
bar(x,y)
axis equal        
aviobj = addframe(aviobj,gcf);       
drawnow 
end
viobj = close(aviobj)

```
One way to do this is to [print](http://www.mathworks.com.au/help/techdoc/ref/print.html) the figure to an image, and then stitch the resulting image sequence into a video. [ffmpeg](http://ffmpeg.org/) and [mencoder](http://www.mplayerhq.hu/) are great tools for doing this. There are some great resources for describing this if you know the right search terms. I like this [one](http://electron.mit.edu/~gsteele/ffmpeg/) 

In mencoder, you could stitch your images together with a command like:

```
mencoder "mf://*.jpg" -mf fps=10 -o test.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800

```