Programming Pete
Programming Pete

Reputation: 37

Matlab: Add folder and subfolders persistent to path

I have a Matlab directory in my Code folder like this: ~/Code/Matlab/

I want the whole content of this folder (and its subfolders) added permanently to the Matlab-path. So that, when I add a new file/ folder into this folder or its subfolders it gets added automatically to the path.

I know how to add a folder permanent to the path but when I add subfolders/ files to it, they are getting not added.

Is this possible and if yes how?

Upvotes: 3

Views: 9597

Answers (3)

Another solution is to add the path with your startup folder. I have my userpath folder under version control with Git, and I have folders and submodule folders inside of it with functions that I use throughout projects. I include the following line in my startup file: addpath(genpath(userpath)). This adds all of those functions to my path as soon as MATLAB opens.

Upvotes: 1

Sam Roberts
Sam Roberts

Reputation: 24127

You can use the following commands:

addpath(genpath('~/Code/Matlab/'));
savepath

This will add your folder, and all its subfolders, to the path. However, if you subsequently add a new subfolder, it will not automatically be added to the path, and you'll need to run the commands again.

I'm afraid there is no "add this folder, its subfolder, and all future subfolders" command.

If this starts to feel repetitive, you could consider creating a shortcut with those commands, and adding it to the MATLAB toolstrip.

Upvotes: 5

Richard
Richard

Reputation: 276

You need to use genpath for the subfolders, i.e.

addpath(genpath('YourFolder'));
savepath

Then, all the files in those folders (even newly added ones) will be permanently available.

Upvotes: 2

Related Questions