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

This question already has an answer here:

This is a real newbie question, so apologies in advance for may seem a very dumb question ... I'm trying to understand the various ways in which information can be retained in a notebook between sessions, using DynamicModule[] etc. Understanding how a good MMA user would solve the following simple task would be really helpful:

Say I want to load a video file and then create a simple slider to scroll through the frames. This works:

frames = Import["myvideofile.avi", {"Frames", All}]; 
Manipulate[frames[[f]], {f, 1, Length[frames],1}]

But, say I want to remember which frame the slider was left at between Mathematica sessions, how would I do that elegantly? If I re-open the code above, there's an error because 'frames' isn't defined until the video is imported.

In other words, upon re-opening the notebook, the first thing I'd like to happen is for 'frames' to be imported. I'm speculating that I need DynamicModule, with Initialization but have tried many different ways and can't get it to work.

share|improve this question

marked as duplicate by Kuba, m_goldberg, rcollyer, Bob Hanlon, Dr. belisarius Apr 28 '15 at 15:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Check SaveDefinitions -> True option of Manipulate and as well as the Initialization possibility. – PlatoManiac Sep 12 '12 at 14:07
You may also use simply ListAnimate[frames]which should remember its content across session. Re-using those will be more tricky though. – Yves Klett Sep 12 '12 at 15:21
up vote 5 down vote accepted

I guess the following will do what you want

Manipulate[frames[[f]], {f, 1, Length[frames], 1},SaveDefinitions -> True]

and this is faster in this case than importing the frames through Initialization option of Manipulate.

enter image description here

You can see while opening the notebook Slider remains in the same place as it was when the notebook was closed for the last time. The second version involving Initialization also does the job you want but it takes much time to load in the first place. This happens as Initialization needs first to import your data. In such time consuming cases we often need to override the initialization time out using SynchronousInitialization -> False.

share|improve this answer
Thanks, that's exactly it. – Cuboid Sep 12 '12 at 14:34

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