1
$\begingroup$

I have a Mathematica notebook which I Open and Evaluate by hand. It Exports some data and then Closes.

I now wanna Open, Run and Close the exact same Notebook 100 or 1000 times in a row to get a lot of data.

How to do program Mathematica to do this operation for me?

$\endgroup$
  • $\begingroup$ @Moo, the notebook does a calculation which depends on random numbers. I need to run the same notebook many, many times to generate a lot of data $\endgroup$ – Nigel1 Jun 30 '19 at 16:47
  • $\begingroup$ @Moo What I would like is to reproduce the calculation of one notebook many times. To do that, I want to open, run and close the same notebook 10000 times in a row. Is it possible in mathematica? $\endgroup$ – Nigel1 Jun 30 '19 at 16:50
  • 2
    $\begingroup$ Why not just run the calculation as many times as you want within the notebook? $\endgroup$ – Rohit Namjoshi Jun 30 '19 at 17:04
  • 1
    $\begingroup$ Why is it not so easy? $\endgroup$ – lirtosiast Jun 30 '19 at 19:18
  • 1
    $\begingroup$ @Nigel1 you can turn your code into a package, generally with very little trouble. After you've done that, calling a package many, many times is very, very easy. $\endgroup$ – b3m2a1 Jun 30 '19 at 21:21
3
$\begingroup$

I suspect that Rohit is correct that there is probably a better way than executing repeatedly from an external notebook, but here is one way to do it. First, create your notebook. For testing, I created the following in a notebook called randInt.nb. This does a random calculation and then saves a file.

r = RandomInteger[10];
Export[NotebookDirectory[] <> "test" <> 
  ToString[RandomInteger[10000]] <> ".txt", r]

To call and execute this repeatedly, create a notebook called test.nb which has contents:

Table[NotebookEvaluate[NotebookDirectory[] <> "randInt.nb"], {i, 5}]

This executes the code in randInt.nb 5 times, as can be verified because it creates 5 text files.

$\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.