Why is "Set Path" not retaining changes to %USERPROFI​LE%\Docume​nts\MATLAB in R2025a?

I hope to move the path "C:\Users\*****\Documents\MATLAB" to the bottom of my paths using the Set Path tool from the MATLAB toolstrip:
- I open the Set Path window, move the folder C:\Users\*****\Documents\MATLAB to the bottom (so that my project gitlab directories appear at the top), check the "Save path for future use" box, and click Apply and OK. 
- However, when I restart MATLAB, the same folder appears "C:\Users\*****\Documents\MATLAB" back to the top of paths. 
Why is this happening?

 Accepted Answer

The directory (%USERPROFILE%\Documents\MATLAB) is the default userpath in MATLAB. It is where MATLAB expects users to save their own scripts, functions, and projects. For more information, please see the MathWorks documentation explaining the MATLAB startup folder.
If you enter the "userpath" command in the MATLAB command window, you will see the same directory. The userpath function returns a user-specific folder that MATLAB adds to the search path at startup. On Windows, by default, this folder is %USERPROFILE%\Documents\MATLAB. By design, this is a special folder: it will always be at the top of the MATLAB path as long as the user has not changed it to point elsewhere or disabled it as their userpath. In your scenario, the "Save Path" function is working as intended. The reason %USERPROFILE%\Documents\MATLAB appears at the top after restarting MATLAB is because the userpath is always added to the top of the path during startup. 
It is not recommended to move the default userpath to the bottom of the paths, as it may cause unexpected behavior or conflicts. MATLAB is designed to prioritize the userpath so that user-defined functions and scripts are easily accessible and take precedence over other files. Moving it to the bottom could result in MATLAB not finding your scripts or using the wrong versions of functions, especially if there are name conflicts with files in other directories.
If you would want to change the startup folder, you can do so in MATLAB settings following the steps in the previous link (under section Change Startup Folder).
If there are functions in the startup folder that override those in your GitLab folder, there are a couple of options:
1. Move the files that contain the overriding functions out of the startup folder/userpath. (RECOMMENDED)
2. Manually move the GitLab folders to the top of the path after launching MATLAB.
3. Change userpath.
4. Change the startup folder.

More Answers (0)

Categories

Products

Release

R2025a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!