Is it possible to call other Mathematica scripts from my current Mathematica notebook?

All the examples that I find online and on this site refer to using C programmes or other programmes within Mathematica, but I actually just want to call another Mathematica script so as to compartmentalise the calculations and make everything tidier.

So I'd like to define my function in a separate notebook, and call it with an argument from my current directory. Matlab style.

  • 1
    $\begingroup$ Have a look at packages e.g. BeginPackage $\endgroup$ – Sascha Nov 23 '16 at 10:50
  • 1
    $\begingroup$ The standard way is to write those functions in .m file and Get them wherever are needed. You can also use NotebookEvaluate for notebooks but then you have to take care to not have to much of not relevant stuff in such notebook, or to tag definitions properly. $\endgroup$ – Kuba Nov 23 '16 at 10:52
  • $\begingroup$ But how do I give it an argument? $\endgroup$ – SuperCiocia Nov 23 '16 at 11:02
  • $\begingroup$ It is not clear to me what you want to achieve. Can you explain more? What do you mean by "compartmentalise" and "call it with an argument"? Maybe give a concrete example of your imagined workflow with the concrete commands you imagine using. I can't tell if you want to define functions, you want to make reusable packages, or if you want to run code in a separate Mathematica process. $\endgroup$ – Szabolcs Nov 23 '16 at 11:04
  • 2
    $\begingroup$ @SuperCiocia reference.wolfram.com/language/tutorial/DefiningFunctions.html + linked tutorials? $\endgroup$ – Kuba Nov 23 '16 at 11:11

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.