How do I automatically add folders to the MATLAB path on startup when using batch mode?

86 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 14 Sep 2023
Edited: MathWorks Support Team on 14 Sep 2023
There are several ways you can add folders to the MATLAB path automatically every time you start MATLAB in batch mode.
Refer to the MATLAB documentation for an overview of general ways to add folders at startup:Add Folders to the MATLAB Search Path at Startup
For options that work well with batch mode, please see below.
NOTE: Starting in R2019b, the '-r' option is no longer recommended for non-interactive use. Use the '-batch' option in non-interactive scripting or command line workflows. Do not use this option with the -r option.
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

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!