MATLAB: Is the modified path not saved in MATLAB

addclearclearedMATLABpathpath2rcsaveset

I add a path using the "Set Path" GUI, and then save it. When I exit MATLAB and restart it, the added paths are no longer on the search path.

Best Answer

The MATLAB path information is saved in the file "pathdef.m". When the "Save" button in the "Set Path" GUI is pressed, the location of the file pathdef.m is determined using the output of the function WHICH.
If there is a file called pathdef.m inside one of the directories that were just added to the top of the MATLAB search path, then this file is used to save the changes to the path instead of using the built-in file $MATLABROOT\toolbox\local\pathdef.m (where $MATLABROOT is your root MATLAB directory).
This can be verified by calling the following right after saving the path changes:
which pathdef -all
Normally, only one file should be found:
$MATLABROOT\toolbox\local\pathdef.m
If multiple files are found, then the path changes are saved to the file that appears topmost.
Always avoid using file names that collide with built-in MATLAB files. The newly added directories could also be moved to the bottom of the search path, this way the function WHICH will find $MATLABROOT\toolbox\local\pathdef.m first, and will save the path changes there.