How can I configure a user-specific MATLAB path on a shared computer?

44 views (last 30 days)
I have a machine that multiple users log into and use the same MATLAB installation on. How can I configure a user-specific MATLAB path for a computer with multiple logins?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 14 May 2025
Edited: MathWorks Support Team on 14 May 2025
The MATLAB search path is initialized at startup from a configuration file called pathdef.m. The system-wide pathdef.m file is located in the MATLAB installation path, which on Windows typically is:
C:\Program Files\MATLAB\RXXXXx\toolbox\local\pathdef.m
The following options describe several ways to manage customized, user-specific paths:

Option 1: Add folders to MATLAB Path at startup or via projects 

If it can be ensured that the system pathdef.m file is protected from modification by users, the recommended approach is to add custom paths at startup. This allows each user to layer their own folders on top of the default, version-specific MATLAB search path without affecting other users.
To automate this, users can create a personal startup.m file containing 'addpath' commands in their MATLAB userpath folder (usually C:\Users\username\Documents\MATLAB). Alternatively, utilize a user-specific environment variable. For more information, see: Add Folders to the MATLAB Search Path at Startup.
A great option for collaborative environments is to add folders to the MATLAB path on a project basis. Learn more about project paths here: MATLAB Projects and Simulink Projects.

Option 2: Set up a user-specific pathdef.m

Each user can maintain a personal pathdef.m in their MATLAB user folder. This method gives each user full control over their MATLAB search path.
NOTE: Do not use this option if multiple MATLAB versions are used. Upgrading MATLAB will require  pathdef.m to be updated for each user.
Follow the steps below to configure personal MATLAB paths for each user on a shared computer:
1. Start MATLAB under the user account you wish to configure.
2. Confirm that the current pathdef.m file is in the MATLAB installation folder:
>> which -all pathdef C:\Program Files\MATLAB\RXXXXx\toolbox\local\pathdef.m
3. If you want to start with a clean path, reset the MATLAB path to factory defaults by running:
>> restoredefaultpath >> rehash toolboxcache >> savepath
4. To determine the current userpath folder, call userpath:
>> userpath
The typical userpath location on Windows is C:\Users\username\Documents\MATLAB. For more information, see: userpath Folder on the Search Path.
5. Change to your userpath folder and save your own pathdef.m file using the savepath command:
>> cd(userpath) >> savepath pathdef.m
6. Verify that the new pathdef.m in the userpath comes first on the search path:
>> which pathdef.m -all C:\Users\username\Documents\MATLAB\pathdef.m C:\Program Files\MATLAB\RXXXXx\toolbox\local\pathdef.m
7. Now the user can use the Current Folder Browser, the "Set Path" dialog, or the addpath command to customize your MATLAB, and save the changes to your personal pathdef.m file. See: Change Folders on Search Path.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!