5
votes

How can I add a Matlab search path for all users on a Linux system?

I am managing a Linux computer that is shared by several people. I want to place some Matlab *.m files at a path (for example, /usr/local/matlab/our_matlab_scripts/) which everyone has a read access permission. I also want to add this path to the Matlab search paths of all users so that they can start using the Matlab files immediately.

As a single user, I learned that I can add a search path by Matlab 'addpath' command or from the file menu of Matlab, for example. However, so far I could not find a way to do it as an administrator for all the current and future users at once.

I would be grateful if you could kindly teach me.

1
@Jonas the question at the link seems to be concerned with a user-specific customization, rather than a system-wide customization that applies to all users. I saw much information in Matlab official help as well as third party web sites about the former case, but my question here has been concerned about the latter, system-wide case. - norio
The answer refers to startup.m. If you put that into $matlabroot/toolbox/local of the Matlab installation, the settings are done for all users. This option is much preferable over editing matlabrc.m, both for setting up a new install and for maintenance. - Jonas
@Jonas Thank you for the comment. Please let me understand why it is better to create startup.m than to edit matlabrc.m. Is there a convention that a new version of Matlab is shipped without startup.m? If so, does it mean that an administrator can basically just copy $matlabroot/toolbox/local/startup.m of old installation to $matlabroot/toolbox/local/ of new installation (and edit it for minor modification)? Or, did you imply other reasons? - norio
Matlab doesn't come with startup.m. Thus, on a new install, you simply copy the file from the old installation to the new (I actually copy two files, startup.m and a file it depends on). Also, since all user modifications are in a separate file, it is much easier to maintain, since you don't have to hunt through many, many lines of code in matlabrc.m to figure out where possibly someone might have changed something (at the beginning, at the end, somewhere in between)? - Jonas

1 Answers

4
votes

If you look at this thread:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/112560

you will find that there is a file called matlabrc.m that is executed at startup. It looks for the startup.m file that users can have. One could put the addpath commands in this file and it should work for all users.