MATLAB: How to automatically add folders to the MATLAB path on startup

batchMATLABmodepathtoolsstartup

I would like to automatically add folders to the MATLAB path on startup.

Best Answer

There are several ways you can add folders to the MATLAB path automatically every time you start MATLAB in batch mode. Please see below:
1. Create a file called startup.m in your MATLAB path. This file is executed when MATLAB opens. Inside you can place the ADDPATH commands and any other variables or scripts you wish you execute on start up.
2. You can permanently add them by typing "pathtool" in the MATLAB command prompt or browsing to "File -> Set Path..."
3. If you call MATLAB from a DOS/terminal prompt, you can type:
matlab -r addpath('your_path_here')
4. Create a script in the MATLAB path, for example, 'addme.m', which predefines the folders you wish to add to the MATLAB path. Type this when you load MATLAB:
matlab -r addme
Note that there should be no spaces in your commands after the '-r' parameter. For example; this will correctly calculate 'c' when starting MATLAB:
matlab -r a=1,b=2,c=a/b
while a space between 'c' and the comma will not:
matlab -r a=1,b=2, c=a/b