How to Set up Matlab's userpath in Terminal?

I want to set Matlab's userpath etc the following in Terminal, instead of doing it in GUI Matlab session.

userpath('/home/masi/Documents/bin/matlab/')

This thread is continua 2 of the thread How do I specify the MATLAB editor keybindings programmatically about startup.m where I can set some other things. I cannot find about it in Documentation so it must be in the undocumented part of Matlab because I know this feature can be done.

My proposal after Suever's answer

Run just once after the installation

echo "export MATLAB_USE_USERWORK=1" >> $HOME/.bashrc

matlab -nodesktop -nosplash -r \ 
    "userpath('/home/masi/Documents/bin/matlab/'); exit;"

Problem with userpath and addpath

See test codes here. Some other configurations have to be applied too.

Matlab: 2016a
System: Linux Ubuntu 16.04

Upvotes: 0

Views: 952

Answers (1)

Suever
Suever

Reputation: 65430

On Linux, the startup.m file should be located within the folder in which you were when you launched MATLAB from the command line.

On Linux® platforms, the default startup folder is the folder from which you started MATLAB.

If you want to use userpath as the startup folder instead of the current directory, you can specify that you'd like to use the userpath via the environment variable MATLAB_USE_USERWORK=1. This will by default point it at $HOME/Documents/MATLAB (or an alternate location if that was set within MATLAB).

To specify the userpath as the startup folder, set the value of the environment variable MATLAB_USE_USERWORK to 1 before startup. By default, userpath is userhome/Documents/MATLAB, and MATLAB automatically adds the userpath folder to the top of the search path upon startup. To specify a different folder for userpath, and for other options, use the MATLAB userpath function.

More info in the documentation

As a side note, if you need to run a MATLAB command from the terminal, it is possible to run MATLAB without the UI and have it execute the necessary command.

matlab -nodesktop -nosplash -r 'commands_here; exit;'

Upvotes: 1

Related Questions