Main Content

savepath

Save current search path

Description

savepath saves the current MATLAB® search path to an existing pathdef.m file in the current folder. If there is no pathdef.m file in the current folder, then savepath saves the search path to the first pathdef.m file on the current path. If there is no such file on the current path, then savepath saves the search path to the pathdef.m file that MATLAB located at startup.

On a Windows® system with User Account Control (UAC) enabled, you might be prompted to allow the update operation because it requires administrator-level permission.

In MATLAB Online™, changes to the path are automatically saved. Therefore, calling savepath is not necessary.

savepath folderName/pathdef.m saves the current search path to pathdef.m located in the folder specified by folderName. If you do not specify folderName, then savepath saves pathdef.m in the current folder.

Use this syntax if you do not have write access to the current pathdef.m file.

To automatically use the saved search path in a future session, specify folderName as the MATLAB startup folder.

example

status = savepath(___) additionally indicates if the operation is successful, using any of the input arguments in the previous syntaxes. The status output is 0 when savepath is successful, and 1 otherwise.

Examples

collapse all

Save the current search path to pathdef.m located in the folder, I:/my_matlab_files.

savepath I:/my_matlab_files/pathdef.m

Input Arguments

collapse all

Folder name, specified as a string array or character vector. folderName can be a relative or absolute path.

Example: C:\myFolder

Tips

  • To display the paths to all pathdef.m files in the current folder and on the current search path, use which.

    which pathdef.m -all
    The savepath command updates the first pathdef.m file in this list.

  • To save the search path programmatically each time you exit MATLAB, use savepath in a finish.m file.

Version History

Introduced before R2006a