Main Content

movie

播放录制movie frames

Description

example

movie(M)plays the movie frames in arrayMonce. To create a movie frame from the current figure or axes, seegetframe.

example

movie(M,n)plays the moviennumber of times. You can specifynas a numeric array, where the first element of the array specifies the number of times to play the movie, and the remaining elements make up a list of frames to play consecutively in the movie.

example

movie(M,n,fps)specifies the number of frames per secondfpsat which to play the movie.

example

movie(h,...)plays the movie centered in the figure or axes identified by the figure or axes objecth. Specifying the figure or axes enables MATLAB®to fit the movie to the available size.

example

movie(h,M,n,fps,loc)plays the movie at the position specified by a four-element arraylocin the current figure.

Examples

collapse all

Use thegetframefunction in a loop to record frames of thepeaksexample function, then play the movie frames once.

Create afigureobjecth. Initialize the surface plot of thepeaksfunctionZ. Customize the figure axes.

h = figure; Z = peaks; surf(Z) axistightmanualax = gca; ax.NextPlot ='replaceChildren';

Preallocate a 40-element arrayMto store the movie frames.

loops = 40; M(loops) = struct('cdata',[],'colormap',[]);

For each iteration ofj, capture each plot of functionXas an individual frame. Store the frame inM.

Set the'Visible'property of the figure object to'off'to hide the surface plots while calculatingX.

h.Visible ='off';forj = 1:loops X = sin(j*pi/10)*Z; surf(X,Z) drawnow M(j) = getframe;end

Set the'Visible'property of the figure to'on'and play the movie inMonce.

h.Visible ='on'; movie(M);

Figure contains an axes object. The axes object contains an object of type surface.

View the figure plots while they are calculated. Play the movie array once.

Create afigureobjecthand initialize the surface plot. Customize the figure axes.

h = figure; Z = peaks; surf(Z) axistightmanual

Figure contains an axes object. The axes object contains an object of type surface.

ax = gca; ax.NextPlot ='replaceChildren';

Preallocate a 40-element arrayMto store the movie frames.

loops = 40; M(loops) = struct('cdata',[],'colormap',[]);

Capture each plot of functionXas an individual frame and store them inM.

forj = 1:loops X = sin(j*pi/10)*Z; surf(X,Z) drawnow M(j) = getframe;end

Play the movie inMonce.

movie(M);

Figure contains an axes object. The axes object contains an object of type surface.

Play four frames of the movie array twice.

Create afigureobjecthand initialize the surface plot. Customize the figure axes.

h = figure; Z = peaks; surf(Z) axistightmanualax = gca; ax.NextPlot ='replaceChildren';

Preallocate a 40-element arrayMto store the movie frames.

loops = 40; M(loops) = struct('cdata',[],'colormap',[]);

Capture each plot of functionXas an individual frame and store them inM.

Set the'Visible'property of the figure object to'off'.

h.Visible ='off';forj = 1:loops X = sin(j*pi/10)*Z; surf(X,Z) drawnow M(j) = getframe;end

Set the'Visible'property of the figure to'on'. Play the first, fifteenth, twenty-third, and thirty-sixth frames in the movie in consecutive order twice. Set the movie to play 12 frames per second.

h.Visible ='on'; movie(M,[2 1 15 23 36],12);

Figure contains an axes object. The axes object contains an object of type surface.

Specify the number of frames per second at which to play the movie.

Create afigureobjecthand initialize the surface plot. Customize the figure axes.

h = figure; Z = peaks; surf(Z) axistightmanualax = gca; ax.NextPlot ='replaceChildren';

Preallocate a 40-element arrayMto store the movie frames.

loops = 40; M(loops) = struct('cdata',[],'colormap',[]);

Capture each plot of functionXas an individual frame and store them inM.

Set the'Visible'property of the figure object to'off'.

h.Visible ='off';forj = 1:loops X = sin(j*pi/10)*Z; surf(X,Z) drawnow M(j) = getframe;end

Set the'Visible'property of the figure to'on'. Play the movie once at 6 frames per second.

h.Visible ='on'; movie(M,1,6);

Figure contains an axes object. The axes object contains an object of type surface.

Play the movie frames in the bottom left corner of the figure.

Create afigureobjecthand initialize the surface plot. Customize the figure axes.

h = figure; Z = peaks; surf(Z) axistightmanualax = gca; ax.NextPlot ='replaceChildren';

Preallocate a 40-element arrayMto store the movie frames.

loops = 40; M(loops) = struct('cdata',[],'colormap',[]);

Set the'Visible'property of the figure object to'off'. Capture each figure in handlehas an individual frame and store them inM.

h.Visible ='off';forj = 1:loops X = sin(j*pi/10)*Z; surf(X,Z) drawnow M(j) = getframe(h);end

Set the'Visible'property of the figure to'on'. Play the movie inMonce at 12 frames per second and with an offset of 30 pixels in the x and y directions. Specify handlehto play the movie in the current figure.

h.Visible ='on'; movie(h,M,1,12,[30 30 0 0]);

Figure contains an axes object. The axes object contains an object of type surface.

Input Arguments

collapse all

一系列电影帧, specified as an array of structures, where each structure contains the image data captured in the current figure or axes as they appear on the screen. Each row inMcorresponds to one movie frame.

You can use thegetframefunction to capture and store the image data as a structure with the fieldscdataandcolormap. For more information on thecdataimage property and thecolormapobject, seeImage Propertiesandcolormap.

Number of times to play movie in the figure, specified as a numeric array. If you do not specifyn,moviewill only play the movie once. Ifnis negative, each cycle is shown forward then backward.

If you specifynas a vector, the first element is the number of times to play the movie, and the remaining elements make up a list of frames to play in the movie.

For example, ifMconsists of four movie frames andnis an array with elementsn = [10 4 4 2 1], thenmovieplays the movie inMten times, and the movie consists of the fourth frame, followed by the fourth frame again, followed by the second frame, and finally the first frame.

Frames per second, specified as a numeric scalar. If you do not specifyfps,moviewill play 12 frames per second. If your machine cannot achieve the speed that you specify asfps, it will play the movie as fast as possible.

Graphics object handle, specified as an axes handle or a figure handle. The default handle ofhisgca, which returns the current axes or chart for the current figure. For more information on thegcafunction, seegca.

If you want to play the movie in the figure instead of the axes, specify the figure handle (orgcf) as the first argument:movie(figure_handle,...).

Location vector, specified as a four-element numeric array,[x y 0 0], where the lower left corner of the movie frame is anchored at the coordinates specified by the first two elements in the array. The coordinates specified inlocare in relation to the lower left corner of the figure or axes specified by handle h, and are in units of pixels. Themoviefunction ignores the last two elements ofloc.

Tips

  • Themoviefunction uses a default figure size of 560-by-420 and does not resize figures to fit movies with larger or smaller frames. To accommodate other frame sizes, you can resize the figure to fit the movie.

  • Buffering the movie places all frames in memory. As a result, on Microsoft®Windows®and perhaps other platforms, a long movie (on the order of several hundred frames) can exhaust memory, depending on system resources. In such cases an error message is issued:

    ??? Error using ==> movie Could not create movie frame

    You can abort a movie by typingCtrl-C.

Version History

Introduced before R2006a