path - View or change search path - MATLAB (original) (raw)
View or change search path
Syntax
Description
path
displays the current MATLAB® search path. The displayed path includes the path saved inpathdef.m
, installed add-ons and support packages, and folders temporarily added by addpath.
path([newpath](#d126e1284891))
changes the search path tonewpath
.
path([oldpath](#d126e1284948),[newfolder](#d126e1284984))
adds the folder newfolder
to the end of the search path. Ifnewfolder
is already on the search path, thenpath(`oldpath`,`newfolder`)
moves newfolder
to the end of the search path. To add multiple folders, use the addpath function.
path([newfolder](#d126e1284984),[oldpath](#d126e1284948))
adds the folder newfolder
to the beginning of the search path. If newfolder
is already on the search path, thenpath(`oldpath`,`newfolder`)
moves newfolder
to 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
Suppose you have MATLAB R2017a installed. Display the search 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
inmy_files
.
oldpath = path; path(oldpath,'my_files') my_function
Restore the previous search path.
Input Arguments
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, ifnewpath
containsc:\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 thepathdef.m
file. You can add these folders topathdef.m
by callingsavepath
.
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 theEnvironment section, click Set Path.
You can also use the addpath function to add multiple folders to the search path.
Version History
Introduced before R2006a