Main Content

path

View or change search path

Description

example

pathdisplays the MATLAB®search path, which is stored inpathdef.m.

example

path(newpath)changes the search path tonewpath.

example

path(oldpath,newfolder)adds the foldernewfolderto the end of the search path. Ifnewfolderis already on the search path, thenpath(oldpath,newfolder)movesnewfolderto the end of the search path. To add multiple folders, use theaddpathfunction.

example

path(newfolder,oldpath)adds the foldernewfolderto the beginning of the search path. Ifnewfolderis already on the search path, thenpath(oldpath,newfolder)movesnewfolderto the beginning of the search path.

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 folderc:\tools\goodstuffto the bottom of the search path on a Microsoft®窗户®system.

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

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

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

Temporarily add the foldermy_filesto the search path and then runmy_functioninmy_files.

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

Restore the previous search path.

路径(媒介上)

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, ifnewpathcontainsc:\matlab\..\work, the new MATLAB search path containsc:\work.

Data Types:char|string

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

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

Alternative Functionality

As an alternative to thepathfunction, use the Set Path dialog box. To open the Set Path dialog box, on theHometab, in theEnvironmentsection, clickSet Path.

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

Introduced before R2006a