# animationToFrame

Return structure of frames from animation objects

## Syntax

``frames = animationToFrame``
``frames = animationToFrame(fig)``
``frames = animationToFrame(___,Name,Value)``

## Description

example

````frames = animationToFrame` returns a structure array of frames from animation objects. The animation objects must be created using the `fanimator` function.```

example

````frames = animationToFrame(fig)` returns a structure array of frames from animation objects in the figure `fig`.```

example

````frames = animationToFrame(___,Name,Value)` uses the specified `Name,Value` pair arguments. Use this option with any of the input argument combinations in the previous syntaxes.```

## Examples

collapse all

Create an animation of a moving circle, and return specific frames of the animation.

First, create two symbolic variables, `t` and `x`. The variable `t` defines the time parameter of the animation. Use `t` to set the center of the circle at `(t,1)` and `x` to parameterize the perimeter of the circle within the range `[-pi pi]`. Create the circle animation object using `fanimator`. Set the x-axis and y-axis to be equal length.

```syms t x fanimator(@fplot,cos(x)+t,sin(x)+1,[-pi pi]) axis equal```

By default, `fanimator` generates an animation object with 10 frames per unit time within the range of `t` from 0 to 10. The default animation object contains a total of 101 frames. Use the command `playAnimation` to play the animation.

Next, return a structure array of frames from the animation object by using `animationToFrame`.

`frames = animationToFrame` ```frames=1×101 struct array with fields: cdata colormap ```

The structure `frames` contains two fields. The `cdata` field stores the image data as an array of `uint8` values.

Reconstruct the animation frames by using the `imshow` function. For example, display the 50th frame and the last frame of the animation.

`imshow(frames(50).cdata)` `imshow(frames(101).cdata)` Create a moving circle animation object and a timer animation object. Return the generated animation frames in reverse order.

First, create two symbolic variables, `t` and `x`. The variable `t` defines the time parameter of the animation. Create a figure window for the animation.

```syms t x fig1 = figure;```

Create a circle animation object using `fanimator`. Use `t` to set the center of the circle at `(t,1)` and `x` to parameterize the perimeter of the circle within the range `[-pi pi]`. Set the x-axis and y-axis to be equal length.

```fanimator(@fplot,cos(x)+t,sin(x)+1,[-pi pi]) axis equal```

Next, use the `text` function to add a piece of text to count the elapsed time. Use `num2str` to convert the time parameter to a string.

```hold on fanimator(@(t) text(8,3,"Timer: "+num2str(t,2))) hold off```

By default, `fanimator` creates stop-motion frames with 10 frames per unit time within the range of `t` from 0 to 10. The default animation object contains a total of 101 frames. Use the command `playAnimation` to play the animation.

Next, return a structure array of frames from the animation in figure `fig` by using `animationToFrame`. Return the animation frames in reverse order by setting the `'Backwards'` option to `true`. Set the frame rate per unit time to 2 to return a total of 21 frames.

`frames = animationToFrame(fig1,'Backwards',true,'FrameRate',2)` ```frames=1×21 struct array with fields: cdata colormap ```

The structure `frames` contains two fields. The `cdata` field stores the image data as an array of `uint8` values.

Reconstruct the animation frames by using the `imshow` function. For example, display the first frame and the 11th frame of the animation in a new figure window.

```fig2 = figure; imshow(frames(1).cdata)``` `imshow(frames(11).cdata)` ## Input Arguments

collapse all

Target figure, specified as a `Figure` object. For more information about `Figure` objects, see `figure`.

### Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside quotes. You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example: `'Backwards',true,'AnimationRange',[-2 5]`

Range of the animation time parameter, specified as a two-element row vector. The two elements must be real values that are increasing.

Example: `[-2 4.5]`

Frame rate, specified as a positive value. The frame rate defines the number of frames per unit time when you returning animation frames as a structure array.

Example: `20`

Backward option, specified as a logical value (boolean). If you specify `true`, then the function returns the animation frames backwards or in reverse order.

Example: `true`

## Output Arguments

collapse all

Animation frames, returned as a structure array with two fields:

• `cdata` — The image data stored as an array of `uint8` values. The size of the image data array depends on your screen resolution.

• `colormap` — The colormap. On true color systems, this field is empty.

The `animationToFrame` function returns a structure of animation frames in the same format as the output returned by the `getframe` function.
{"ft_lang_label":"__label__en","ft_lang_prob":0.6265284,"math_prob":0.9748595,"size":1665,"snap":"2020-24-2020-29","text_gpt3_token_len":414,"char_repetition_ratio":0.16977724,"word_repetition_ratio":0.0,"special_character_ratio":0.23303303,"punctuation_ratio":0.12275449,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95186853,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12],"im_url_duplicate_count":[null,2,null,2,null,2,null,2,null,2,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-07-11T22:48:16Z\",\"WARC-Record-ID\":\"<urn:uuid:298bc766-25a0-42a8-bd24-355a2e6e83a5>\",\"Content-Length\":\"93882\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:192d2d62-8562-4473-9e7a-ebd4e938cec4>\",\"WARC-Concurrent-To\":\"<urn:uuid:cf565fa8-9b0c-4bcc-bc58-9a08c41b88a3>\",\"WARC-IP-Address\":\"23.223.252.57\",\"WARC-Target-URI\":\"https://la.mathworks.com/help/symbolic/animationtoframe.html\",\"WARC-Payload-Digest\":\"sha1:NOWJLNJLHHC6YJRWEAO4CMWM6CYHYSSL\",\"WARC-Block-Digest\":\"sha1:PGMRRLZR5EU4QRTHTAMCOSFQQI6VPG2I\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-29/CC-MAIN-2020-29_segments_1593657129257.81_warc_CC-MAIN-20200711224142-20200712014142-00081.warc.gz\"}"}