1

I basically have a bunch of user-defined functions that I can run when I use Matlab, because I can specify the working directory. However when I use Jupyter Notebook those functions are undefined. How do I specify the working directory in this case?

Either a permanent solution or a session solution is OK. However my preference is the session solution, so that I do not have to specify back the working directory all the time to its default value.

3
  • 1
    Use addpath maybe? Commented Mar 18, 2016 at 20:39
  • that worked! perfect Commented Mar 18, 2016 at 20:49
  • I posted a more complete answer. Commented Mar 19, 2016 at 1:03

2 Answers 2

4

You can use the function addpath to add a directory containing M-files to the MATLAB search path.

Some relevant links to documentation pages:

Sign up to request clarification or add additional context in comments.

Comments

1

If you are editing the functions, you can use bash script inside Jupyter notebook. This way you can have your functions in front of you. With the example code below, they will be written down on the same path. But you can save them anywhere at the end, again using %%shell.

%%shell
echo "
y = func(x) ... % here you copy the function m file
" > func.m

Also you can implement the Amro's answer inside the notebook with %%shell. This way you can have a session solution within the Jupyter notebook.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.