The system-wide pathdef.m. file containing the MATLAB search path is located in the MATLAB installation folder, which typically is:
C:\Program Files\MATLAB\RXXXXx\toolbox\local\pathdef.m
When the default installation folder (C:\Program Files) is protected by Windows User Account Control (UAC), standard users do not have write access to pathdef.m. This helps prevent accidental or unauthorized changes to the system-wide MATLAB path.
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.. To run MATLAB as an administrator, right-click on the MATLAB icon and choose "Run as administrator".
NOTE: If you are on a shared computer, this will permanently set the path for all MATLAB users on that system, unless they have configured MATLAB to use a personal copy of pathdef.m. For more information, see:
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. the userpath, which is typically "C:\Users\<USERNAME>\Documents\MATLAB"). This can be achieved by typing:
>> edit(fullfile(userpath,'startup.m'))
on the MATLAB Command Window. Then, on the "startup.m" file, write:
addpath('desiredFolderFullPath')
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 a copy of pathdef.m in your MATLAB userfolder
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 userpath folder. By default, the MATLAB userpath folder is the Windows user directory, where each user has full read/write access. You can use the 'savepath' command as shown below to save copy of pathdef.m to the user directory:
>> cd(userpath)
>> savepath pathdef.m
Below are the steps to change the location of pathdef.m using the 'Set Path' dialog: