Main Content

savepath

Save current search path

Description

savepathsaves the current MATLAB®search path to an existingpathdef.mfile in the current folder. If there is nopathdef.mfile in the current folder, thensavepathsaves the search path to the firstpathdef.mfile on the current path. If there is no such file on the current path, thensavepathsaves the search path to thepathdef.mfile 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.

InMATLAB Online™, changes to the path are automatically saved. Therefore, callingsavepathis not necessary.

example

savepathfolderName/pathdef.msaves the current search path topathdef.mlocated in the folder specified byfolderName. If you do not specifyfolderName, thensavepathsavespathdef.min the current folder.

Use this syntax if you do not have write access to the currentpathdef.mfile.

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

status = savepath(___)additionally indicates if the operation is successful, using any of the input arguments in the previous syntaxes. Thestatusoutput is0whensavepathis successful, and1otherwise.

Examples

collapse all

Save the current search path topathdef.mlocated in the folder,I:/my_matlab_files.

savepathI:/my_matlab_files/pathdef.m

Input Arguments

collapse all

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

Example:C:\myFolder

Tips

  • To display the paths to allpathdef.mfiles in the current folder and on the current search path, usewhich.

    whichpathdef.m-all
    Thesavepathcommand updates the firstpathdef.mfile in this list.

  • To save the search path programmatically each time you exit MATLAB, usesavepathin afinish.mfile.

Introduced before R2006a