By default, the 'pathdef.m' file is located in the '<matlabroot>/toolbox/local' directory, where <matlabroot> is the directory displayed after entering the following command in the MATLAB Command Window:
Another possible, supported location for 'pathdef.m' may be the userpath, where userpath is the directory displayed after entering the command in the MATLAB Command Window:
To move the 'pathdef.m' file from its default location to another location, it can be manually copied from this directory and placed in an arbitrary directory, or you can call 'savepath' with an input argument that specifies the full path:
>> savepath folderName/pathdef.m
In order for MATLAB to use the copied 'pathdef.m' file at initialization, create a MATLAB file titled 'startup.m' and place it in the userpath folder. Copy the lines of code below to the file. If a 'startup.m' file already exists in userpath, add the lines of code to the end of the file:
startdir = pwd;
pathdir = '<MODIFIED_PATH>';
cd(pathdir)
path(pathdef)
cd(startdir)
Make sure to modify the string marked "MODIFIED_PATH" in the above code to the directory to which the 'pathdef.m' file was copied. The 'startup.m' script will be automatically executed upon MATLAB initialization.
WARNING: If you intend to use multiple MATLAB releases, do not place "pathdef.m" in your userpath, or use "startup.m" to relocate "pathdef.m."
"pathdef.m" is unique to each release, whereas the default userpath containing "startup.m" is shared across all releases. Following the workflow outlined above may result in loading the same "pathdef.m" file for every release, leading to a corrupted MATLAB session.
If your end goal is to add custom paths to MATLAB's search path, you can write the commands below in your "startup.m" instead:
addpath('customPath1',...
'customPath2',...
'customPathN')
where "customPathX" represents the specific paths you wish to add. When using the same default userpath for each MATLAB installation, these custom paths will be added across all your installed MATLAB releases.
For a full overview of ways to customize your MATLAB path at startup, see: