How will running the "restoredefaultpath" and "savepath" commands affect my custom paths and how do I back up my custom paths?
136 views (last 30 days)
MathWorks Support Team on 16 Dec 2014
I setup custom paths from within MATLAB but now need to restore the default path. How does the "restoredefaultpath" command affect my custom paths and how can I back them up before running it?
MathWorks Support Team on 21 Jul 2021
Edited: MathWorks Support Team on 21 Jul 2021
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:
which -all pathdef
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":
More Answers (2)
I have perform your solution. When i try the savepath command i still have an issue This is the output error Warning: C:\Program Files (x86)\MATLAB\R2010bSP2\toolbox\local\pathdef.m not found. Toolbox Path Cache is not being used. Type 'help toolbox_path_cache' for more info Undefined function or variable 'ispc'. Warning: MATLAB did not appear to successfully set the search path. To recover for this session of MATLAB, type "restoredefaultpath;matlabrc". To find out how to avoid this warning the next time you start MATLAB, type "docsearch problem path" after recovering for this session. Warning: Duplicate directory name: C:\Program Files (x86)\MATLAB\R2010bSP2\toolbox\local. Warning: Initializing Handle Graphics failed in matlabrc. This indicates a potentially serious problem in your MATLAB setup, which should be resolved as soon as possible. Error detected was: MATLAB:UndefinedFunction Undefined function or method 'colordef' for input arguments of type 'double'. > In matlabrc at 100 Warning: Initializing Java preferences failed in matlabrc. This indicates a potentially serious problem in your MATLAB setup, which should be resolved as soon as possible. Error detected was: MATLAB:UndefinedFunction Undefined function or method 'usejava' for input arguments of type 'char'. > In matlabrc at 123 Warning: Failed to add default profiler filters. > In matlabrc at 179 >> restoredefaultpath >> which -all pathdef 'pathdef' not found. >> savepath Warning: Unable to save path to file ''. > In savepath at 162
Please tke in mind that it is ablocking issue fior us and please contact us by phone as soon as possible
At this time we have resolved by ourself the pathdef issues Nethertheless we still have a blocking issues. Focus on the installation: - we have lauched the Matlab installer - we have download from your website (after identification using our login and licence) the zip of Simulink We lay the stress on the fact the Simulink is not installed on our PC despite of a full installation Can you help us and give us a straigt way to install the toolbox because we spent too time for this and we can not wait more... Sorry for the urgence but we are awaiting a more straig solution Feel free to contact me by phone in order to find quickly a solution +33 05 34 61 97 81 Regards