The MATLAB® search path, is a subset of all the folders in the file system. MATLAB uses the search path to locate files used with MathWorks® products efficiently.
The order of folders on the search path is important. When files with the same name appear in multiple folders on the search path, MATLAB uses the one found in the folder nearest to the top of the search path.
By default, the search path includes
userpath folder, which is added to the search path at
startup, and is the default location for storing user files
The folders defined as part of the
The folders provided with MATLAB and other MathWorks products, which are under
matlabroot is the folder displayed when you run
matlabroot in the Command
Class, package, and
private folders should not
be specified explicitly as part of the search path.
You can explicitly add folders to the search path for the files you run. For more information about adding files to the search path, see Change Folders on the Search Path.
userpath folder is first on the search path. By
default, MATLAB adds the
userpath folder to the search path
at startup. This folder is a convenient place for storing files that you use with
userpath folder is platform-specific.
Windows® platforms —
Mac platforms —
Linux® platforms —
Alternatively, to determine or change the current
userpath folder, call
By default, the
userpath folder is also the startup
folder when you start MATLAB by double-clicking either the MATLAB shortcut on Windows systems or the MATLAB application on Mac systems.
MATLABPATH environment variable can contain a list of
additional folders to be added to the MATLAB search path at startup. These folders are placed after the
userpath folder, but ahead of the folders supplied by
MathWorks. By default, the
MATLABPATH environment variable is
not set. For more information on how to set the
environment variable, see Set the MATLABPATH Environment Variable.
There are several ways to determine if files and folders are on the search path. You can either check whether an individual file or folder is on the search path, or you can view the entire search path.
To determine whether a file is on the search path, run
. If the file is on the
search path, MATLAB returns the full path to the file.
To determine whether a file or folder is on the search path, use the Current Folder browser. Files and folders not on the path are dimmed. To ensure the Current Folder browser is set to indicate whether a file or folder in on the search path, right-click any file or folder, and select the Indicate Files Not on Path option.
Hover the pointer over any dimmed file or folder in the Current Folder browser to find out why it is dimmed. A tooltip opens with an explanation. Frequently, the tooltip indicates that the file or folder is not on the MATLAB path. If a tooltip does not appear, it may be disabled. To enable it, go the Home tab and in the Environment section, click Preferences. Then, select MATLAB > Current Folder. Select Show tooltip explaining why files are inaccessible to display the tooltip.
path command to view all the
folders on the MATLAB search path.
Alternatively, use the Set Path dialog box to view the entire MATLAB search path. On the Home tab, in the Environment section, click Set Path. The Set Path dialog box opens, listing all folders on the search path. For more information on using the Set Path dialog box, see Change Folders on the Search Path.
The search path is not the same as the system path. Furthermore, there is no explicit relationship between the MATLAB search path and the system path. However, both paths help in locating files, as follows:
MATLAB uses the search path to locate MATLAB files efficiently.
The operating system uses a system path to locate operating system files efficiently.
MATLAB saves search path information in the
file. This file contains a series of full path names, one for each folder on the
pathdef.m is in
When you change the search path, MATLAB uses it in the current session, but does not update
pathdef.m. To use the modified search path in the current and
future sessions, save the changes using
savepath or the
Save button in the Set Path dialog box. This updates