4
$\begingroup$

ListAnimate is fairly similar to Manipulate, but while Manipulate has a simple way to request an initial value for the manipulation parameter, I haven't found a way to tell ListAnimate to start with a certain value.

Consider a simple example:

ListAnimate[Table[Plot[Sin[p x], {x, -1, 1}], {p, 1, 4}]]  

vs.

Manipulate[Plot[Sin[p x], {x, -1, 1}], {p, Range[1, 4]}]  

These simple examples seem virtually the same (I didn't bother to change the Manipulate Control to a slider), but in fact, they are different. ListAnimate is essentially pre-compiled. In my research, I want to do something similar with very complex plots which take a long time to produce. Manipulate re-calculates it's arguments when the manipulator is adjusted. We don't notice it here because Sin[p x] is so trivial. But with a complicated plot, it's no good. Conversely, with ListAnimate, it may take 15 minutes or more to run the code, once and for all, and then I can quickly scan through all the output smoothly.

I looked through the options for ListAnimate and, for example, I can begin the output paused with ,AnimationRunning -> False.

Is there a way to make the animation begin with not the first element but a chosen one?

TL;DR

Make

ListAnimate[Table[Plot[Sin[p x], {x, -1, 1}], {p, 1, 4}], AnimationRunning -> False]  

begin with output of Plot[Sin[3 x], {x, -1, 1}]

$\endgroup$
  • 1
    $\begingroup$ You could use ListAnimate[RotateLeft[Table[...],n],....] $\endgroup$ – Dr. belisarius Apr 11 '14 at 19:38
  • $\begingroup$ An elegant solution in some cases, most likely (strictly speaking, it does solve the question as I posed it, I guess). The problem is that in my case, the parameter that varies over the table elements is an ordinal quantity (varying, say, from 0 to 1) and doing this shifts it to where the animation bar left to right no longer corresponds to the parameter varying from 0 to 1. $\endgroup$ – Steve Apr 11 '14 at 19:44
  • $\begingroup$ I'm hoping to be able to retain the original order, but simple have the control not begin at the left of the slider, but at a chosen point in the middle perhaps. $\endgroup$ – Steve Apr 11 '14 at 19:45
  • 2
    $\begingroup$ why not frames = Table[Plot[Sin[p x],{x,-1,1}],{p,1,4}]; Manipulate[Part[frames,p],{{p,3},1,4,1}]? If you are going to precompute the frames anyway... $\endgroup$ – chuy Apr 11 '14 at 19:53
  • 1
    $\begingroup$ Also, not completely equivalent, but ... Animate[Plot[Sin[p x], {x, -1, 1}], {{p, 3}, 1, 4, 1}, AnimationRunning -> False] $\endgroup$ – Dr. belisarius Apr 11 '14 at 19:53
3
$\begingroup$

As commented by Dr. belisarius

You can set the initial value by creating the following sentence: {p, 3}.

Animate[Plot[Sin[p x], {x, -1, 1}], {{p, 3}, 1, 4, 1}, 
 AnimationRunning -> False]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.