Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

Add Folders to the MATLAB Search Path at Startup

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 with addpath 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 the MATLABPATH environment variable. :

Windows

To set the MATLABPATH environment variable in Windows®, from the Windows Control Panel, go to System and select Advanced system settings. Click the Environment Variables... button. Click New... 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 and c:\matlab_files\myfolder2, to the MATLABPATH environment variable, enter c:\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 command set 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 and c:\matlab_files\myfolder2, to the MATLABPATH 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 the MATLABPATH 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 or tcsh), the command for setting the MATLABPATH 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.

More About

Was this topic helpful?