MATLAB will read its path from a file called pathdef.m. There may be multiple pathdef.m files on your computer but MATLAB will only read one at a time. MATLAB will read the pathdef.m file in your MATLAB startup folder in your Documents folder first. To determine which pathdef.m file is currently being used by MATLAB, run the command:
Before proceeding, you should backup this file by copying it to a folder outside of your MATLAB path.
The which -all command will list all pathdef.m files that MATLAB can find. The first one on this list is the one MATLAB is currently using.
If you run the "restoredefaultpath" command, MATLAB will remove the current path from this session and will then search through the MATLAB installation directory and add all toolbox folders back to the path for this session. It will only hold this in memory and not save it for future sessions. To make this change permanent, run the command:
The savepath command will save this session's MATLAB path to the pathdef.m that is listed first in the output of which -all pathdef. It will overwrite the existing contents of this file.
How to Back Up Custom Paths
You can back up your active pathdef.m file by moving to a folder that is not on your MATLAB path or by renaming it.
If you have multiple release of MATLAB installed, using a pathdef.m file in your MATLAB startup directory, in your Documents folder, can be problematic. All installed versions will read this pathdef.m by default. This pathdef.m file will be specific to the version of MATLAB in which you last saved the path. In other versions of MATLAB, the paths may not be accurate and this may cause problems starting MATLAB or errors in the MATLAB command window at startup.
To avoid this issue you can instead create a startup.m file that will add your custom paths to MATLAB's path at the beginning of each session without changing the contents of the pathdef.m file. This will allow MATLAB to maintain user-specific custom paths without altering MATLAB's default path for that release. For more details on this, please refer to the below documentation for "addpath":