# movie

## 语法

``movie(M)``
``movie(M,n)``
``movie(M,n,fps)``
``movie(h,...)``
``movie(h,M,n,fps,loc)``

## 说明

``movie(M)` 会将数组 `M` 中的影片帧播放一次。要从当前图窗或坐标区创建影片帧，请参阅 `getframe`。 `

``movie(M,n)` 会将影片播放 `n` 次。您可以将 `n` 指定为数值数组，其中数组的第一个元素指定播放影片的次数，其余元素构成影片中连续播放的帧列表。 `

``movie(M,n,fps)` 指定影片每秒播放的帧数 `fps`。`

``movie(h,...)` 在由图窗或坐标区对象 `h` 所标识的图窗或坐标区中心位置播放影片。指定图窗或坐标区可以使 MATLAB® 将影片调整到合适大小。`

``movie(h,M,n,fps,loc)` 在当前图窗中由四元素数组 `loc` 指定的位置播放影片。`

## 示例

```h = figure; Z = peaks; surf(Z) axis tight manual ax = gca; ax.NextPlot = 'replaceChildren';```

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

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

`h.Visible = 'on';`

`movie(M);`

```h = figure; Z = peaks; surf(Z) axis tight manual```

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

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

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

`movie(M);`

```h = figure; Z = peaks; surf(Z) axis tight manual ax = gca; ax.NextPlot = 'replaceChildren';```

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

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

`h.Visible = 'on';`

`movie(M,[2 1 15 23 36],12);`

```h = figure; Z = peaks; surf(Z) axis tight manual ax = gca; ax.NextPlot = 'replaceChildren';```

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

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

`h.Visible = 'on';`

`movie(M,1,6);`

```h = figure; Z = peaks; surf(Z) axis tight manual ax = gca; ax.NextPlot = 'replaceChildren';```

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

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

`h.Visible = 'on';`

`movie(h,M,1,12,[30 30 0 0]);`

## 提示

• `movie` 函数使用默认尺寸为 560×420 的图窗，而且不会调整图窗尺寸以适应帧偏大或偏小的影片。要适应其他框架尺寸，您可以重新调整图窗大小以适应影片。

• 缓冲影片可将所有帧放入内存中。这样，在 Microsoft® Windows® 及其他平台上，一些很长的影片（数百帧）可能会耗尽内存，这取决于系统资源。这种情况下，可能会发出一条错误消息：

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

您可以输入 Ctrl-C 终止影片。