Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In Fortran, I can use include "file" to insert a piece of code. Is there a similar method in Mathematica?

share|improve this question
1  
Have a look at the docs on packages. –  b.gatessucks Dec 27 '12 at 13:45
    
@b.gatessucks I think that should be an answer... –  acl Dec 27 '12 at 14:43
    
@acl Can't do it right now, please do go ahead. –  b.gatessucks Dec 27 '12 at 17:12

1 Answer 1

The answer is very simple:

Put your external code snippet into a file toInclude.m, for example with the content

Plot[Sin[x],{x,0,Pi}]

Now in the "parent" notebook (assuming it's in the same directory as the code snippet), execute the command

Import["toInclude.m"]

or

<< "toInclude.m"

and you're done. Here are the references for << (Get) and Import.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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