Changing Matlab's Startup Folder in Linux

Changing MATLAB's startup folder in Linux

I don't know the regular way to do this, but the easy way is just settings the userpath to your directory of personal scripts.

In that folder, you put a script startup.m which contains:

cd /path/to/my/startup

It might not look pretty, but this allows you to change the directory depending on other factors. I have seen examples of people who get a prompt at startup that asks 'Which project are you working on?' and depending on their input some files are loaded, the direcotry is changed, etc. Personally, I load settings from different locations depending on what computer MATLAB is working on (home computer, personal computer at my university, computer rooms at university, ...)

edit: Perhaps just a small idea that might help you along with those variables: you can always try to edit the MATLAB start script for Linux (not startup.m but the bash script returned by which matlab in your shell).

changing matlab startup current folder

You can create (or modify) a startup script in your MATLAB root directory (or anywhere on your MATLAB search path) with the exact name of startup.m. All you write in this script will execute each time MATLAB is started. There you can change current folder using cd:

cd('the_starting_root_you_prefer')

And save it. If you want to know your root directory, use matlabroot.

Where is startup.m supposed to be?

The best method, I find, is this. Let's say you want MATLAB to start up in mystartupdir, and you've placed startup.m in that directory.

On Windows, make a shortcut icon to MATLAB, then right-click on it and select Properties. Edit the field Start In. Now, use this icon whenever you want to start MATLAB.

On other platforms, you can run MATLAB with the -sd flag to specify the startup directory:

matlab -sd mystartupdir

If you don't specify a startup directory, MATLAB will use the default specified by the userpath command. You can place your startup.m file there.

setting a default matlab path at startup

You can change which directory MATLAB starts in using the userpath function so that whenever you start up MATLAB, the path will automatically redirect here.

This may be useful if you have MATLAB running on a network per se, and multiple instances can start in the same network directory.

See more from MathWorks here: http://www.mathworks.com/help/matlab/matlab_env/matlab-startup-folder.html


However, if you want to standardize everything so that everyone has access to the same path, you can use startup to add directories / folders to MATLAB's path, but if you want to complete the package, use userpath to get MATLAB to start at a specified directory.

Your startup.m file may look something like this:

addpath('/folder/to/add/one');
addpath('/folder/to/add/two');
addpath('/folder/to/add/three');
addpath('/folder/to/add/four');

Then set your userpath with the function to complete everything:

userpath('/folder/to/start');
addpath('/folder/to/start');

Also make sure you add this new folder to your startup.m file too.

How to set a folder as Current folder for every startup of Matlab?

I finally found it.

You edit a file named startup.m in /matlabrootfolder/toolbox/local and I add cd /Users/ALJI/MATLAB.

It worked, hope this help :)

Running Matlab script on startup

As stated in the docs, startup.m can be anywhere on the path.

Create a startup.m file in a folder on the MATLAB search path. Add commands you want executed at startup.

Typically, it can be found in your Documents folder, which you can surely access...

C:\Users\<username>\Documents\MATLAB\startup.m

There must be somewhere you have write access to on your machine... you can set the initial path for Matlab (on startup) in the General Preferences, then place startup.m in that location (so it will definitely be on your path), and let it call any script you want.


Alternatively, you could add a shortcut to have a 1-click solution, which can be run any time (including immediately after startup). See the documentation for more details.

How to select which Matlab version to start from shell or Matlab startup?

To find which Matlab is started by default, type path in the shell (opened by Run->cmd). The first one is the one that is picked if you type Matlab.

From the output of path you also find where your Matlab versions are located. If you don't want to navigate to the respective folder every time, you can make console aliases for the different versions.

EDIT

If you want to solve the problem in a very general sense, I see two possible avenues:

(1) Check the registry for whether Matlab puts something version-specific there that is tied to the path (or ask TheMathWorks).

(2) Parse path for '\bin\64' (or '\bin\32' if it's a 32-bit system) and check whether these folders contain a file called 'matlab'. As part of the installation routine (if the Matlab versions are not in the factory-default locations), start each Matlab, and run ver to find which version it is.

Does matlab have a matlabrc file?

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?

How to set some custom variables on Matlab startup

Create a startup.m script file containing the commands to set up the state that you want. Next, from inside MATLAB, run the command

>> userpath

This will give you a list of one or more user-specific directories (depending on what OS you are using); put your startup.m in any of those directories and it will be found whenever you start MATLAB (startup.m is also found if it is in the directory from which MATLAB is started, but the technique above allows you to start MATLAB from an arbitrary directory and still have startup.m get run).



Related Topics



Leave a reply



Submit