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: