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

146 views (last 30 days)
I am trying to save the MATLAB path on Windows with the User Account Control (UAC) set to "on".
MATLAB is installed in a directory protected by UAC (e.g., C:\Program Files).
If try to execute the function SAVEPATH, my path is not saved and I receive the following warning:
>> savepath
Warning: Unable to save path to file 'C:\Program Files\MATLAB\R2021b\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.
If I try to save the MATLAB path from PATHTOOL ('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 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?
I have full administrative privileges on this computer.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Feb 2022
Edited: MathWorks Support Team on 12 Mar 2022
If MATLAB is installed in the default directory (C:\Program Files\...) with UAC enabled, write access to "pathdef.m" will be blocked.
There are three ways to work around this issue:
1. Temporarily turn UAC off by right-clicking on the MATLAB icon, and selecting "Run as Administrator", or
2. Permanently turn UAC off through the Windows Control Panel, or
3. Install MATLAB outside of the "C:\Program Files" folder.
If you are encountering this issue when using the 'pathtool' dialog, note that you can still make temporary changes to the MATLAB path which persist only for your current session. You can do this by adding a folder with the 'pathtool' and then closing the window without clicking "Save", or by using the 'addpath' function:
For more information on the UAC, which was introduced with Windows Vista, see the following Microsoft article:
  3 Comments
A Jorge
A Jorge on 26 Sep 2020
For mac IOS users (and maybe linux), simply go to the Pathdef.m file out of the Matlab Application folder ("go to your applications folder, right click on Matlab and Show Package Contents" on a Mac, under Matlab_R20xxb.app\toolbox\local). Navigate to this folder address, right click pathdef.m file, click get info, unlock the lock with your password at the bottom (you need admin privileges here I believe) and change the Privilege column at the very bottom from Read to Read & Write. You need to restart matlab for the change to take effect.

Sign in to comment.

More Answers (3)

Ed Callway
Ed Callway on 4 Mar 2020
Edited: Ed Callway on 4 Mar 2020
It's 2020, and matlab still can't save the path when you hit "save path" in an actual set-the-path menu?! Yet dozens of other matlab preferences save perfectly as do EVERY OTHER PREFERENCE IN EVERY OTHER WINDOWS PROGRAM EVER. Above is the worst "my first Fisher Price program" set of answers ever:
  1. Turn off UAC 'cause I love viruses
  2. Install outside of programs directory because I want to be different than EVERY OTHER PROGRAM ON EARTH
How about:
  1. Split the user defined paths from the core paths needed for boot up
  2. Put user defined stuff in the USER directory like every other program on earth
Why am I so angry? I lose 10 min a day on this ridiculous issue. Money back please.
  2 Comments
yunhui zhou
yunhui zhou on 19 Mar 2020
Or add your path to "startup.m" which will automatically run when MATLAB launch.

Sign in to comment.


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.

Tarek Bekir
Tarek Bekir on 17 Mar 2019
  1. Go to C:\Program Files\MATLAB\R2017b\bin\ or wherever the matlab is installed then find the matlab.exe file.
  2. Right click on matlab.exe , and select properties.
  3. Select compatibility tab.
  4. Tick the Box : Run this program in compatibility mode for: and select for example windowsXP sp3
  5. Tick the box at the bottom "Run this program as an administrator". (This is the important option)
  6. Restart matlab and enjoy!
Hope this might help.

Community Treasure Hunt

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

Start Hunting!