Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have following code

Plot[myvariable x,{x,0,100}

How do I make the animation stop automatically when reaching a defined value?

NOTE: I tried to make it stop by evaluating myvariable in a If expression, but I get the error "An unrecognized option name ("AnimationRunning") was encountered while reading a AnimatorBox."

share|improve this question
Given your example, you could just set AnimationRunning -> True, AnimationRepetitions -> 1 – Jens Jan 10 '13 at 19:31
Post is an answer an I will mark as the answer, Thanx for answering so fast :D – elhombre Jan 10 '13 at 19:34
up vote 3 down vote accepted

The condition in your case is to stop at the maximum value of the parameter. This can be achieved by setting the number of animation repetitions to 1 (i.e., no looping):

Animate[Plot[myvariable x, {x, 0, 100}], {myvariable, 0.1, 1}, 
 AnimationRunning -> True, 
 AnimationRepetitions -> 1
share|improve this answer

Mathematica is very flexible when it comes to these sorts of things. You can easily build your own little animation, and add as much complexity to the logic of termination by using Dynamic directly.

For example, this plots Cos[a x] and stops the animation when a>0.2.

Do[p = Plot[Cos[a x], {x, 0, 100}, Frame -> True, 
   FrameLabel -> {{None, None}, {x, 
      Style[Column[{"doing my own animation !", Cos[a x]}, 
        Alignment -> Center], 14]}}, GridLines -> Automatic];
 If[a > 0.2, Break[]]; (*condition to stop*)
 {a, 0.1, 1, .01}

Mathematica graphics

share|improve this answer
+1 for a method I really don't think I would have considered. – Mr.Wizard Jan 11 '13 at 1:11
+1 Because you did the work to allow a more general stopping condition than the question asked for. – Jens Jan 11 '13 at 1:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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