path - View or change search path - MATLAB (original) (raw)
View or change search path
Syntax
Description
path
displays the MATLAB® search path, which is stored in pathdef.m
.
path([newpath](#d126e1266384))
changes the search path tonewpath
.
path([oldpath](#d126e1266441),[newfolder](#d126e1266477))
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](#d126e1266477),[oldpath](#d126e1266441))
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
Display Search Path
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 New Folder to Search Path on Windows
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 New Folder to Search Path on UNIX
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 Folder to Search Path
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
newpath
— New MATLAB search path
character array | string array
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
oldpath
— Existing MATLAB search path
character array | string array
Existing MATLAB search path, specified as a character array or string array returned by the path
command.
Data Types: char
| string
newfolder
— New folder
character vector | string scalar
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 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