I have two notebooks; one main notebook which calls another notebook several times in a loop. I want to delete the assignments of variables in the sub-notebook which is called from the main one.

Using ClearAll["Global`*"] in the sub-notebook also clears the main notebook variable assignments, which I want to protect; I just want to clear the assignments in the sub-notebook.

How could I solve this?

  • 1
    $\begingroup$ I strongly recommend to convert your notebook to a function e.g. proc1[]: = Module[{localvariables...}, ...]. You will have more flexibility and no questions like this anymore. $\endgroup$ – Kuba Jul 28 '16 at 6:36
  • $\begingroup$ @Kuba Will I write the procedure proc1[] into the notebook cell or elsewhere ? The problem is I use notebooks since it allows to use mathematical superscript and subscripts, which makes the calculations easy to follow and while writing a procedure in a .m script; could I use Basic Math Assistant Pallette ? $\endgroup$ – ahmethasim Jul 28 '16 at 6:43
  • $\begingroup$ You can define it in a notebook, no problem. Just be sure to evaluate this definition in a fresh session. $\endgroup$ – Kuba Jul 28 '16 at 6:45
  • $\begingroup$ This is a good start tutorial/DefiningFunctions $\endgroup$ – Kuba Jul 28 '16 at 6:46
  • 1
    $\begingroup$ Set the default CellContext for the notebooks to Notebook. Any variables that you need in Global` then explicitly set with the context name, e.g. Global`x = 2. $\endgroup$ – Edmund Aug 1 '16 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.