I have this Manipulate:
Manipulate[Plot[Sin[a x], {x, 0, 2 Pi}], {a, 0, 3}]
Now, I realize I had mistyped the expression and it's actually x^2
instead. I go back and fix it, but when I evaluate the cell again, the value of a
reverts to default/zero.
I've tried multiple things from various Q&A: adding SaveDefinitions -> True
, saving parameter to a global variable within the Manipulate
block, using bookmarks, but none of them achieved the effect of having the Manipulate
start up with a previously-set control value.
Interesting, I find that saving the parameter to a global variable, and then initialize the parameter with the same global variable solves the problem, i.e., Manipulate
can remember the manipulated parameter from a previous run. If I add the option SaveDefinitions -> True
, the value is also saved between sessions.
Below is an example: a
remains at the same value even when the expression in Manipulate
was changed and the cell was evaluated.
I went to the chat room to ask people if doing this is OK. I was told that I should not do this. What kind of potential issues would I have with this method? And if it's bad, is there another method to achieve the same result, i.e., preventing Manipulate
from resetting control values after each evaluation?
Manipulate
like this one I find your approach rather clever. $\endgroup$