Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does matlab have a matlabrc file?

Today I stumbled upon this thread:

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

The question is basically how to make Matlab read your startup.m file regardless of where you start your matlab session.

One of the solutions offered was:

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

What I ended up doing in my system (OS X) was to add a startup.m file in:

/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

That way users have the option of creating the hidden folder ~/.matlabrc and inside it they can put the file startup.m. In this startup file they can tell matlab what to execute whenever they start Matlab regardless of the directory where they started it. An example of what I added to my own personal startup.m file is

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

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

The question is: Did Matlab already provided a special file like the one I created or did I just go through all this trouble to accomplish what I wanted? If the answer is the second option I gave, then, why doesn't Matlab provide this? It is such a pain in the ass to add directories to the Matlab path whenever you do not have admin permissions and I do not want to carry my startup.m file to every directory I go to. Can someone shed some light into this please?

like image 543
jmlopez Avatar asked Jun 16 '12 02:06

jmlopez


1 Answers

You can save the pathdef file (which stores all the paths you add) to a custom directory. The problem however is that when matlab starts, it doesn't automatically know which custom directory you used in the previous session.

But that's where the MATLABPATH environment variable comes in. Because this allows to set the matlab starting path yourself. In linux this is simply done by setting this environment variable MATLABPATH before starting matlab (from a terminal / in your .bashrc / ...)

export MATLABPATH=$HOME/.matlab

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

EDIT

I tested out if adding startup.m to that MATLABPATH directory worked, ie: does matlab run that startup file? ... and it does. I think it doesn't work for you, because there is another startup.m file in some other (higher priority) directory (probably matlabroot), so that gets precedence. My only startup file is in MATLABPATH, so there is only one choice.

EDIT2

Nope, I added startup to matlabroot directory, and still my own startup file in .matlab gets run. Are you sure you set the MATLABPATH correctly before you started matlab?

like image 189
Gunther Struyf Avatar answered Oct 27 '22 10:10

Gunther Struyf