This part of the Tutorial deals with Movies.

 

 

Matlab offers the ability to save a sequence of plots of any type , 2-D or 3-D and then play the sequence back as a movie. This provides yet another dimension to the plot. One obvious movie type takes a

3-D plot and slowly rotate it so it can be viewed from a variety of angles. Another example can be a sequence of plots showing the solution of some problem as a parameter value changes.

 

In Matlab ,the functions movie , moviein and getframe provide the tools required to capture and play movies.

 

moviein : It creates an array called Frame Matrix to store movie frames in.

 

M = MOVIEIN(N) creates a matrix large enough to hold N frames of a movie based on the current axis. The matrix has enough rows to store N copies of the output from GETFRAME, one in each column.

 

Example: To generate a movie with n frames,

M = moviein(n);

for j=1:n

plot_command // get the plot of the graphics

M(:,j) = getframe // Add the frame obtained above to the matrix

end

movie(M) // Play the movie

 

getframe : It gets the snapshot of the current figure. Typically it is used in a loop and captured into a matrix and played later with the movie command.

 

movie: It plays back the recorded sequences of frames. It takes a Matrix argument of which it is going to play.

 

movie(M) // Plays M for one time

movie(M,N) // Plays M for N times

 

In simple the approach to create and play movies in three steps is as follows:

  1. Create the frame matrix,
  2. For each movie frame create the plot and capture it in the frame matrix,
  3. Play the movie back from the frame matrix.

 

 

Example :

 

 

[X,Y,Z] = peaks(30);

surfl(X,Y,Z) // draws the surface with highlights from a light source.

axis([-3 3 -3 3 -10 10])

axis off

shading interp

colormap(hot)

m = moviein(15);// creates an array m of size 15

 

for i = 1:15

view(-37.5 + 24*(i-1),30)

m(:,i)= getframe;// captures the frame into the matrix

end

 

movie(m) // Play the movie