3
$\begingroup$

Suppose you have some notebooks, they work for a family of related tasks, each one doing a certain task. Lets say Notebook 1 gets two inputs from its variables in11 and in12, and produces one output to out1. The other Notebook 2 gets two inputs from its variables in21 and in22, and produces one output to out2.

How can we set up a kind of master notebook where just the decision to select a specific
task should be made, the assignments to the variables are made, and the result of the calculation is shown. The two working notebooks themselves should be in the same folder on your disk, and a call from the open master notebook pipes them their respective inputs and outputs.

$\endgroup$
1
  • 2
    $\begingroup$ Any specific reason for not using a package? $\endgroup$
    – Yves Klett
    Mar 26, 2013 at 15:30

1 Answer 1

6
$\begingroup$

Simple example. In nb1.nb put, say, the Input cell:

in11 = "In 11  ";
in12 = "In 12";
out1 = Row[{in11, in12}]

And in nb2.nb put the Input cell:

in21 = "In 21  ";
in22 = "In 22";
out2 = Row[{in21, in22}]

In master.nb put the Input cell:

dir = NotebookDirectory[];
NotebookEvaluate[FileNameJoin[{dir, "nb1.nb"}]];
NotebookEvaluate[FileNameJoin[{dir, "nb2.nb"}]];
Column[{out1, out2}]

Save all three notebooks in the same directory (or modify the code in master.nb accordingly). Then evaluating that cell in master.nb will produce

In 11  In 12
In 21  In 22

which means, of course, that the Input cells in both nb1.nb and nb2.nb have been evaluated, so that values have been given to out1 and out2, respectively.

$\endgroup$
2
  • $\begingroup$ I like this. . .And if you want to pass some variable values from nb1.nb to master.nb in the first place? . . .So the master.nb acts like a function. . .Get a value and return a value. $\endgroup$ Mar 28, 2013 at 7:36
  • $\begingroup$ What makes all this work is the fact that, by default, all values set in one notebook are available to all other notebooks at the same Mathematica kernel session. (Unless you take steps to restrict the Context of a notebook.) $\endgroup$
    – murray
    Mar 28, 2013 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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