TransWikia.com

How to have a common input for different nb file

Mathematica Asked on August 27, 2021

I have a set of five files. Each file takes a common input. But I need to change the input and run the files. The output of some file are used in other files. So how to do this. And also is there any ways to run all the files in some sequence. i.e just run one after the other in some sequence, and the final output will have the expected result.

One Answer

The easiest solution is using NotebookEvaluate.

I will provide a minimal example, assuming all files are saved in the same directory.

I have a file notebook1.nb which depends on the value of some variable a, e.g.

(* notebook1.nb *)
Export["output.dat", a^2];

The notebook notebook0.nb can set the variable a and evaluate notebook1.nb

(* notebook0.nb *)
SetDirectory[NotebookDirectory[]];
a = 2;
NotebookEvaluate[
  FileNameJoin[{NotebookDirectory[], "notebook1.nb"}]
  ];

Note that SetDirectory is not strictly necessary, but ensures that output.dat is written to the same directory.

One can check that output.dat really gives the desired output

# output.dat
4

Answered by Natas on August 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP