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

278 visualizzazioni (ultimi 30 giorni)
I use MATLAB on a Windows computer where User Account Control (UAC) is enabled. I installed MATLAB in a directory protected by UAC, for example, C:\Program Files.
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?

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 26 Set 2023
Modificato: MathWorks Support Team il 26 Set 2023
By default, the "pathdef.m" file containing the MATLAB search path is located in the MATLAB installation folder. If MATLAB is installed in the default directory (C:\Program Files\...) with User Account Control (UAC) enabled, write access to "pathdef.m" may be blocked.
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. By doing this, you will permanently set the path for all MATLAB users on that system, provided that they have read access to "C:\Program Files\MATLAB\RXXXXx\toolbox\local\pathdef.m".
To run MATLAB as an administrator, right-click on the MATLAB icon and choose "Run as administrator".

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. "C:\Users\<USERNAME>\Documents\MATLAB").
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 pathdef.m in your MATLAB startup folder

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 startup folder. By default, the MATLAB startup folder is the Windows user directory, where each user has full read/write access. You can use 'savepath' command as shown below to save pathdef.m to the user directory:
>> savepath('C:\Users\<USERNAME>\Documents\MATLAB\pathdef.m')
where <USERNAME> is your Windows user name.
Below are the steps to change the location of pathdef.m using the 'Set Path' dialog:
Refer to the following documentation to learn more about the MATLAB startup folder:
  2 Commenti
K E
K E il 6 Giu 2016
Even when I 'Run as Administrator' (#1), I still can't save paths in R2015a.
Abhishek Pandey
Abhishek Pandey il 6 Giu 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

Accedi per commentare.

Più risposte (1)

yunhui zhou
yunhui zhou il 19 Mar 2020
Modificato: yunhui zhou il 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.

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by