Main Content

rewindAnimation

Rewind previously played animation objects

Description

example

rewindAnimationrewinds previously played animation objects by restoring the animation time parameter to its initial value. The animation objects must be created using thefanimatorfunction.

example

rewindAnimation(fig)rewinds animation objects in the figurefig.

Examples

collapse all

Create an animation of a moving circle and rewind it usingrewindAnimation.

First, create two symbolic variables,tandx. The variabletdefines the time parameter of the animation. Usetto set the center of the circle at(t,1)andxto parameterize the perimeter of the circle within the range[-pi pi]. Create the circle animation object usingfanimator. Set thex-axis andy-axis to be equal length.

symstxfanimator(@fplot,cos(x)+t,sin(x)+1,[-pi pi]) axisequal

由enterin播放动画g the commandplayAnimation. By default,playAnimationplays the animation within the range oftfrom 0 to 10. You can rewind the animation by usingrewindAnimation.rewindAnimationrestores the animation time parameter to its initial value att = 0and shows the starting animation frame.

rewindAnimation

Create an animation of a moving circle with a timer, and rewind the animation usingrewindAnimation.

First, create two symbolic variables,tandx. The variabletdefines the time parameter of the animation. Create a figure window for the animation.

symstxfig = figure;

Create the circle animation object usingfanimator. Usetto set the center of the circle at(t,1)andxto parameterize the perimeter of the circle within the range[-pi pi]. Set the range of the animation time parameter to[4 8]. Set thex-axis andy-axis to be equal length.

fanimator(@fplot,cos(x)+t,sin(x)+1,[-pi pi],'AnimationRange',[4 8]) axisequal

Next, add a timer animation object. Use thetextfunction to create a piece of text to count the elapsed time. Usenum2strto convert the time parameter to a string.

holdonfanimator(@(t) text(8,3,"Timer: "+num2str(t,2)),'AnimationRange',[4 8]) holdoff

Play the animation in figurefigbetween 4 and 8 seconds by entering theplayAnimationcommand.

playAnimation(fig,'AnimationRange',[4 8])

You can rewind a previously played animation by usingrewindAnimation.rewindAnimationrestores the animation time parameter to its initial value att = 4and shows the starting animation frame.

rewindAnimation(fig)

Input Arguments

collapse all

Target figure, specified as aFigureobject. For more information aboutFigureobjects, seefigure.

Introduced in R2019a