Does Matlab have a matlabrc file?

Today I came across this topic:

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

The question is how to get Matlab to read the startup.m file no matter where you start the Matlab session.

One of the proposed solutions:

One solution would be to ask the system administrator to add a few lines to "matlabrc.m", which adds some predefined folder in the home user directory to the MATLAB path (say ~ / .matlabstart). Then each user can have their own file "startup.m" inside this folder.

What I ended up on my system (OS X) was to add the startup.m file to:

/Applications/MATLAB_R2011a.app/toolbox/local/ 

In this startup.m file, I added:

 if exist([getenv('HOME') '/.matlabrc/startup.m']) run([getenv('HOME') '/.matlabrc/startup.m']); end 

Thus, users have the opportunity to create a hidden folder ~/.matlabrc , and inside it they can put the file startup.m . In this startup file, they can tell matlab what to do when they start Matlab, regardless of the directory in which they started it. An example of what I added to my own startup.m file,

 addpath(genpath('/Users/jmlopez/matlabcode/')) 

Now I can add as many folders inside this directory, and all of them will be added to the path every time I start Matlab automatically, without changing the path.

The question is, did Matlab provide a special file similar to the one I created, or did I just go through all these problems to accomplish what I wanted? If the answer is the second option I gave, then why doesn't Matlab provide this? It’s a pain in the ass to add directories to the Matlab path whenever you do not have administrator privileges, and I don’t want to transfer my startup.m file to every directory I go to. Can someone shed some light on this, please?

+8
path rc matlab startup
source share
1 answer

You can save the pathdef file (which saves all the paths you add) to the user directory. However, the problem is that when you start matlab, it does not automatically know which user directory was used in the previous session.

But this is where the MATLABPATH environment variable enters. Because it allows you to set the Matlab start path yourself. On linux, this is simply done by setting this MATLABPATH environment variable before running matlab (from terminal / in your .bashrc / ...)

 export MATLABPATH=$HOME/.matlab 

Thus, you can allow all users to have their own pathdef file, which solves the problem of having to add them manually at startup.

EDIT

I tested if adding startup.m to this directory MATLABPATH, i.e. Does matlab execute this boot file? ... and it does. I think this will not work for you because there is another startup.m file in another directory with a higher priority (possibly matlabroot ), so it takes precedence. My only boot file is in MATLABPATH, so there is only one choice.

EDIT2

No, I added the download to the matlabroot directory, and yet my own launch file in .matlab starts up. Are you sure you configured MATLABPATH correctly before starting Matlab?

+6
source share

All Articles