littleO
littleO

Reputation: 1002

Multiple pathdef files in Matlab?

Suppose two different Matlab users share a computer and they each want to be able to save and load their own Matlab paths. (Or, a single user wants to use different paths at different times.) What's the easiest way to handle this?

Should there be multiple pathdef files? Alternatively, should they each have a script that calls restoredefaultpath and then uses addpath to add new paths?

Upvotes: 3

Views: 772

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112749

You can use the startup.m file for that.

When starting up, Matlab executes the file matlabrc.m, which is the master startup file, and is common for all users. Among other things, this file

  1. Sets the first entry of the path as the user-folder of the current user, that is, the user that started Matlab. (This is done by calling pathdef, which in turn calls userpath); and then
  2. Looks for a startup.m file in the path, end executes if it exists.

Therefore you can place a user-specific startup.m file in each user's folder, and Matlab will run the appropriate file depending on which user started Matlab. In that file you can set the path on a per-user basis, and do other user-related stuff.

Upvotes: 4

Related Questions