MATLAB: How to move the ‘pathdef.m’ file from its default location to another location in MATLAB 8.1 (R2013a)

changechoosefilelocationMATLABpathpathdefpermissionprefdirstartup

I would like to put my 'pathdef.m' path file in an arbitrary directory instead of the default directory.

Best Answer

The ability to select an arbitrary location for the MATLAB path file 'pathdef.m' is not available in MATLAB 8.1 (R2013a). One possible workaround is detailed below.
By default, the 'pathdef.m' file may be located in either the '$MATLABROOT/toolbox/local' directory or the '$USERPATH' directory, where $MATLABROOT and $USERPATH are the directories displayed after entering the commands
matlabroot
and
userpath
at the MATLAB command line respectively.
The 'pathdef.m' file can be manually copied from either of these directories and placed in an arbitrary directory. To use the copied 'pathdef.m' file at initialization, create a MATLAB file titled 'startup.m' and place it in the '$USERPATH' directory. 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:
% save starting directory
startdir = pwd ;
% specify arbitrary directory containing pathdef.m
pathdir = '<MODIFY>' ;
% change directory so that target 'pathdef.m' has highest precedence
% in the MATLAB search path
cd(pathdir)
% set the MATLAB search path using PATH
path(pathdef)
% change directory back to the starting directory
cd(startdir)
Make sure to modify the string marked "MODIFY" 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.