By default, the "pathdef.m" file containing the MATLAB user 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" will be blocked.
Temporary Solution for Current MATLAB Session
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 will take effect immediately.
Apply temporary changes by adding a folder with the Set Path dialog and then "Close" the window without clicking "Save":The same can be accomplished programmatically by using the 'addpath' function without calling 'savpath' 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: Add folders automatically at MATLAB startup
- Option 2: Add folders automatically at project startup
- Option 3: Save pathdef.m in your MATLAB startup folder
Option 1: Add folders automatically at MATLAB startup
Other more advanced ways would be to use the MATLABPATH environment variable, or to launch MATLAB from the Windows or Desktop shortcut with additional "addpath" commands.
Refer to the following documentation for an overview of how to specify MATLAB startup options:
Option 2: Add folders automatically at project startup
A variation of Option 1 would be to add folders to the MATLAB path on a project basis using MATLAB Projects and Simulink Projects. Learn more about project paths here:
Option 3: Save pathdef.m in your MATLAB startup folder
If you wish to be able to permanently save the MATLAB path, you need to store pathdef.m in a folder that is not protected by the UAC and where you have full read/write access. In order for MATLAB to use this pathdef.m in future sessions, you need to save pathdef.m in your MATLAB startup folder.
The location of the MATLAB startup folder depends on how you start MATLAB. If you launch MATLAB by double-clicking on a Windows desktop icon shortcut, you can specify the MATLAB startup directory in the HOME Tab under Preferences > MATLAB > General > Initial Working Folder.
A recommended location for the MATLAB startup directory is the Windows user directory:C:\Users\jondoe\Documents\MATLAB
Refer to the following documentation to learn more about the MATLAB startup folder: