|On this page…|
The search path, or path is a subset of all the folders in the file system. MATLAB® software uses the search path to efficiently locate files used with MathWorks® products. MATLAB can access all files in the folders on the search path.
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
Folders provided with MATLAB and other MathWorks products
These folders are under matlabroot/toolbox, where matlabroot is the folder displayed when you type matlabroot in the Command Window.
The MATLAB userpath
The userpath folder is a location for storing files that MATLAB adds to the search path at startup.
You can explicitly add folders to the search path for the files you run.
Class, package, and private folders are not on the search path.
The userpath folder is first on the search path, above the folders supplied by MathWorks. By default, MATLAB adds the userpath folder to the search path at startup. Therefore, the userpath is convenient for storing files where MATLAB can access them.
The userpath consists of a primary path, and on Macintosh and UNIX® platforms, it also contains a secondary path. The primary path is only one folder, but the secondary path can contain multiple folders.
The default primary userpath folder is platform-specific.
On all platforms except Windows® platforms released before Windows Vista™, the default primary userpath is Documents/MATLAB.
On Windows platforms released before Windows Vista, it is My Documents/MATLAB.
On Mac platforms, it is $home/Documents/MATLAB.
On UNIX platforms, it is$home/Documents/MATLAB if $home/Documents exists.
To determine the current userpath, call userpath.
By default, the userpath folder is the startup folder when you start MATLAB by double-clicking either the MATLAB shortcut on Windows systems, or the MATLAB application on Macintosh systems.
There are several ways to determine if files and folders are on the search path.
For a file, run which filename. If the file is on the search path, MATLAB returns the full path to the file.
Use the Current Folder browser to determine if files or folders in the current folder are on the search path:
In the Current Folder browser, right-click any file or folder, and ensure there is a check mark next to Indicate Files Not on Path .
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.
Run the path command to view 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.
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 the search path information in the pathdef.m file. The pathdef.m file is a series of full path names, one for each folder on the search path, separated by a semicolon (;).
By default, pathdef.m is in matlabroot/toolbox/local.
When you change the search path, MATLAB uses it in the current session. 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 the pathdef.m file.