Add Folders to the MATLAB Search Path at Startup - MATLAB & Simulink (original) (raw)
There are two ways to add folders to the MATLAB® search path at startup. You can either use a startup.m
file or you can set the MATLABPATH
environment variable.
Use a startup.m
File
The startup.m
file is for specifying startup options. You can add folders to the search path by including addpath
statements in a startup.m
file. For example, to add the specified folder,/home/_`username`_/mytools
to the search path at startup, include this statement in a startup.m
file:
addpath /home/username/mytools
For more information on creating a startup.m
file withaddpath
statements, see Startup Options in MATLAB Startup File.
Set the MATLABPATH
Environment Variable
You can also add folders to the search path at startup by setting theMATLABPATH
environment variable. :
Windows
To set the MATLABPATH
environment variable in Windows®, from the WindowsControl Panel, go to System and selectAdvanced system settings. Click theEnvironment Variables... button. ClickNew... or Edit... to create or edit the MATLABPATH
environment variable. In the dialog box that appears, set the variable name to MATLABPATH
and the variable value to a semicolon-separated list of folders you want to add to the search path. For example, to add two folders,c:\matlab_files\myfolder1
andc:\matlab_files\myfolder2
, to theMATLABPATH
environment variable, enterc:\matlab_files\myfolder1;c:\matlab_files\myfolder2
as the variable value. Click OK to set the variable and exit the dialog box. Restart MATLAB for the new settings to take effect.
To set the environment variable from a command window, run the commandset MATLABPATH=_`folders`_
, where_folders
_ is a semicolon-separated list of folders. For example, suppose that you want to add two folders,c:\matlab_files\myfolder1
andc:\matlab_files\myfolder2
, to theMATLABPATH
environment variable. Run the command
set MATLABPATH=c:\matlab_files\myfolder1;c:\matlab_files\myfolder2
Once the environment variable is set, you must start MATLAB from the same command window for the settings to take effect. The environment variable persists only as long as the command window is open.
UNIX and Mac
To set the MATLABPATH
environment variable in UNIX® and Mac, in a terminal, run the command export MATLABPATH=_`folders`_
, where_folders
_ is a colon-separated list of folders.
For example, suppose that you want to add two folders,/home/j/Documents/MATLAB/mine
and/home/j/Documents/MATLAB/research
, to theMATLABPATH
environment variable on a UNIX platform. Run the command
export MATLABPATH=/home/j/Documents/MATLAB/mine:/home/j/Documents/MATLAB/research
Once the environment variable is set, you must start MATLAB from the same shell for the settings to take effect. The environment variable persists only as long as the shell remains open.
Note
If you are using a C shell (csh
ortcsh
), the command for setting theMATLABPATH
environment variable is setenv MATLABPATH _`folders`_
.
To add the folders for all future MATLAB sessions, set the MATLABPATH
environment variable as part of your shell configuration script.