Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to send a few Manipulate Plots and regular plots to my advisor in a notebook. I typically Import data into my notebook to generate plots but when I open my file on a new computer, the regular Plots stay but the Manipulate ones are dead, until I Import the data again. Is there any way I can keep the data inside the notebook so when he "enables dynamic" to open the notebook on his computer, that the Manipulate plots become active, just the way the data in regular plots are not lost ?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

SaveDefinitions would work for you I guess.

Try the below code. Execute, then save the notebook it is in. Kill the kernel with Quit[] and reopen the notebook. Content is still there and is manipulable without re-executing.

f = ExampleData[{"Text", "GettysburgAddress"}];

Manipulate[
 ListPlot[(StringLength /@ StringSplit[f])[[;; ;; i]]],
 {i, 1, 5, 1},
 SaveDefinitions -> True
 ]

Mathematica graphics

share|improve this answer
    
In my experience, SaveDefinitions is not as reliable as Initialization, particularly when moving between platforms. –  Mark McClure Oct 7 '12 at 21:22
    
@Sjoerd C. de Vries and Mark McClure. Thanks for both your answers. Since I had to accept one, I went with Sjoreds. Right now I am using SaveDefinitions but when I have to make an important presentation, I will not take a chance and use Initialization. –  Amatya Oct 16 '12 at 6:48
add comment

You could use the Initialization option of Manipulate.

Manipulate[DateListPlot[data[[1 ;; k]],
  Filling -> Axis, PlotRange -> {0, 40}],
  {{k, 10}, 1, Length[data], 1},
  Initialization :> (data = FinancialData["FB", All])]

Alternatively, you could store the data in a separate initialization cell. That is create a cell like so:

Manipulate[DateListPlot[data[[1 ;; k]],
  Filling -> Axis, PlotRange -> {0, 40}],
  {{k, 10}, 1, Length[data], 1}]

And create (anywhere in the notebook) a separate initialization cell like so:

data = FinancialData["FB", All]

Note that this initialization could contain the pre-downloaded data, rather than an import type command. The important issue is that it's cell properties be set to be an initialization cell.

share|improve this answer
    
Using an initialization cell in your alternative method a Dynamic will throw errors until that Initialization cell is evaluated. The only way I've found around this is to set your notebook to evaluate automatically at open. –  kale Oct 8 '12 at 1:02
    
@kale That sounds believable. For that method, I was envisioning a scenario where the notebook is opened with no Output cells - the user could then execute the Input cells to see the output. The point behind the initialization cell would be to contain long input, such as pre-imported data. –  Mark McClure Oct 8 '12 at 1:32
    
@MarkMcClure Thanks a lot for your answer. I used the SaveDefinitions right now and picked it as the accepted answer because that seemed simpler but I will now try your cell initialization method. I'm sorry, I can't believe that it has taken me 8 days to respond. Thanks a lot. –  Amatya Oct 16 '12 at 6:55
add comment

Your Answer

 
discard

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.