Why can't I save my MATLAB path on Windows with User Account Control (UAC) enabled?

70 views (last 30 days)
I use MATLAB on a Windows computer. When I try to execute the function 'savepath' in MATLAB, my path is not saved and I receive the following warning:
>> savepath Warning: Unable to save path to file 'C:\Program Files\MATLAB\R2023a\toolbox\local\pathdef.m'. You can save your path to a different location by calling SAVEPATH with an input argument that specifies the full path. For MATLAB to use that path in future sessions, save the path to 'pathdef.m' in your MATLAB startup folder.
When I try to save the MATLAB path from the 'Set Path' dialog, I get the message:
MATLAB cannot save changes to the path. The path file, pathdef.m, might be read-only or might be in a directory for which you do not have write access. You can save pathdef.m to a different location. In order for MATLAB to use that pathdef.m in future sessions, you need to save it in your MATLAB startup directory (the directory from which you start MATLAB). Would you like to save pathdef.m to another location?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 29 May 2025 at 0:00
Edited: MathWorks Support Team on 6 Jun 2025 at 11:11
The system-wide pathdef.m. file containing the MATLAB search path is located in the MATLAB installation folder, which typically is:
C:\Program Files\MATLAB\RXXXXx\toolbox\local\pathdef.m
When the default installation folder (C:\Program Files) is protected by Windows User Account Control (UAC), standard users do not have write access to pathdef.m. This helps prevent accidental or unauthorized changes to the system-wide MATLAB path.
Note that it is not mandatory to save the MATLAB path for it to take effect in your current MATLAB session. You can make temporary changes to the MATLAB path which will persist for your current session. All changes take effect immediately. In the 'Set Path' dialog, you can just "Close" the window without clicking "Save":
The same can be accomplished programmatically by using the 'addpath' function without calling 'savepath' at the end. See: https://www.mathworks.com/help/matlab/ref/addpath.html
Permanent Solution for Future MATLAB Sessions
If you wish to have a permanent solution that automatically sets your custom MATLAB path for future MATLAB sessions, consider one of the following workarounds:
  • Option 1: Run MATLAB as an Administrator
  • Option 2: Add folders automatically at MATLAB startup
  • Option 3: Add folders automatically at project startup
  • Option 4: Save pathdef.m in your MATLAB startup folder

Option 1: Run MATLAB as an Administrator

On some systems, starting MATLAB as administrator may be sufficient to get write permission to pathdef.m.. To run MATLAB as an administrator, right-click on the MATLAB icon and choose "Run as administrator".
NOTE: If you are on a shared computer, this will permanently set the path for all MATLAB users on that system, unless they have configured MATLAB to use a personal copy of pathdef.m. For more information, see:

Option 2: Add folders automatically at MATLAB startup

One easy solution is to create a startup.m file containing 'addpath' commands and save it in a folder on your MATLAB path (e.g. the userpath, which is typically "C:\Users\<USERNAME>\Documents\MATLAB").
This can be achieved by typing:
>> edit(fullfile(userpath,'startup.m'))
on the MATLAB Command Window. Then, on the "startup.m" file, write:
addpath('desiredFolderFullPath')
You would still not be able to use the 'Set Path' dialog or the 'savepath' command, but the startup.m file provides a lot of flexibility to implement any user-specific customization for your MATLAB sessions. Refer to the following documentation for an overview of startup.m and other more advanced ways to specify MATLAB startup options:

Option 3: Add folders automatically at project startup

A great option for team collaboration is to add folders to the MATLAB path on a project basis using MATLAB Projects and Simulink Projects. Learn more about project paths here:

Option 4: Save a copy of pathdef.m in your MATLAB userfolder

If the ability to use the 'Save Path' dialog or the 'savepath' command is a priority, you can save a personal copy of pathdef.m in your MATLAB userpath folder. By default, the MATLAB userpath folder is the Windows user directory, where each user has full read/write access. You can use the 'savepath' command as shown below to save copy of pathdef.m to the user directory:
>> cd(userpath) >> savepath pathdef.m
Below are the steps to change the location of pathdef.m using the 'Set Path' dialog:
  2 Comments
Abhishek Pandey
Abhishek Pandey on 6 Jun 2016
Hi,
This probably means that you do not have administrator rights in your system. You basically need permissions to edit the pathdef.m file which is in your Windows directory.
Hope this helps!
- Abhishek

Sign in to comment.

More Answers (1)

yunhui zhou
yunhui zhou on 19 Mar 2020
Edited: yunhui zhou on 19 Mar 2020
Please note the following words in error message: " You can save pathdef.m to a different location, In order for MATLAB to user the pathdef.m in future sessions, you need to save it in your MATLAB startup directory (the directory from which you start MATLAB). Would you like to save pathdef.m to another location?".
Just copy and save pathdef.m to your user directory (for example "C:\Users\<Your_Name>\Documents\MATLAB") and you can save your path without messing the MATLAB path for other users of your computer.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!