Main Content

path

View or change search path

Description

path displays the current MATLAB® search path. The displayed path includes the path saved in pathdef.m, installed add-ons and support packages, and folders temporarily added by addpath.

example

path(newpath) changes the search path to newpath.

example

path(oldpath,newfolder) adds the folder newfolder to the end of the search path. If newfolder is already on the search path, then path(oldpath,newfolder) moves newfolder to the end of the search path. To add multiple folders, use the addpath function.

example

path(newfolder,oldpath) adds the folder newfolder to the beginning of the search path. If newfolder is already on the search path, then path(oldpath,newfolder) moves newfolder to the beginning of the search path.

example

p = path(___) returns the MATLAB search path as a character vector. You can use this syntax with any of the input argument combinations in the previous syntaxes.

Examples

collapse all

Suppose you have MATLAB R2017a installed. Display the search path.

path
		MATLABPATH

	C:\Program Files\MATLAB\R2017a\toolbox\matlab\datafun
	C:\Program Files\MATLAB\R2017a\toolbox\matlab\datatypes
	C:\Program Files\MATLAB\R2017a\toolbox\matlab\elfun
	C:\Program Files\MATLAB\R2017a\toolbox\matlab\elmat
	C:\Program Files\MATLAB\R2017a\toolbox\matlab\funfun
	C:\Program Files\MATLAB\R2017a\toolbox\matlab\general
	C:\Program Files\MATLAB\R2017a\toolbox\matlab\iofun
	C:\Program Files\MATLAB\R2017a\toolbox\matlab\lang
	C:\Program Files\MATLAB\R2017a\toolbox\matlab\matfun
...

Add the folder c:\tools\goodstuff to the bottom of the search path on a Microsoft® Windows® system.

oldpath = path;
path(oldpath,'c:\tools\goodstuff')

Add the folder /home/tools/goodstuff to the beginning of the search path on a UNIX® system.

oldpath = path;
path('/home/tools/goodstuff',oldpath)

Temporarily add the folder my_files to the search path and then run my_function in my_files.

oldpath = path;
path(oldpath,'my_files')
my_function

Restore the previous search path.

path(oldpath)

Input Arguments

collapse all

New MATLAB search path, specified as a character array or string array.

MATLAB resolves all path names containing '.', '..', and symbolic links to their target location before adding them to the path. This ensures that each entry in the MATLAB path represents a unique folder location. For example, if newpath contains c:\matlab\..\work, the new MATLAB search path contains c:\work.

Data Types: char | string

Existing MATLAB search path, specified as a character array or string array returned by the path command.

Data Types: char | string

New folder to add to the MATLAB search path, specified as a character vector or string scalar.

Data Types: char | string

Tips

  • Installed Add-ons and support packages are added to the path and will be displayed when path is called but the folders containing the add-ons and support packages do not appear in the pathdef.m file. You can add these folders to pathdef.m by calling savepath.

Alternative Functionality

As an alternative to the path function, use the Set Path dialog box. To open the Set Path dialog box, on the Home tab, in the Environment section, click Set Path.

You can also use the addpath function to add multiple folders to the search path.

Version History

Introduced before R2006a