- 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
Why can't I save my MATLAB path on Windows with User Account Control (UAC) enabled?
100 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 10 de Sept. de 2012
Editada: MathWorks Support Team
el 26 de Sept. de 2023
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?
Respuesta aceptada
MathWorks Support Team
el 26 de Sept. de 2023
Editada: MathWorks Support Team
el 26 de Sept. de 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:
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".
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:
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:
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 comentarios
K E
el 6 de Jun. de 2016
Even when I 'Run as Administrator' (#1), I still can't save paths in R2015a.
Abhishek Pandey
el 6 de Jun. de 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
Más respuestas (1)
yunhui zhou
el 19 de Mzo. de 2020
Editada: yunhui zhou
el 19 de Mzo. de 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.
0 comentarios
Ver también
Categorías
Más información sobre Search Path en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!