Accessing shell environment variables in MATLAB under Ubuntu Linux 10.04

11 views (last 30 days)
I am running MATLAB R2011a under Ubuntu 10.04. When I launch matlab by typing matlab& in a terminal window, I can access shell environment variables that have been set in /etc/profile.
However, when I launch MATLAB from the menu or from an icon (in either case, the .desktop command is "matlab -desktop"), these shell variables are not set.
How can I launch MATLAB from menus or icons and have it see the environment variables?
Thanks.

Answers (4)

Ty Watkins
Ty Watkins on 21 Jan 2022
Ran in to this same issue when I tried to create a menu launch for Matlab on RHEL7 running KDE Plasma. The issue is that if not run from a terminal, it will launch with a non-interative, non-login environment. Instead of going in and trying to move the additoins to the $PATH variable in the .bashrc above the logic that kicks a non-interative bash session out, a simple way is to start a new bash environment similar to what @Walter Roberson posed as his solution. However, I would recommend starting it as an interactive shell and not a login shell. There's not going to be a large difference between the two. The part that was missing is the you have to add the '-c' flag before the string containing the command you want to run. Change the command to the following and you should be good to go.
$SHELL -i -c 'matlab -desktop'
This should load all the environment variables that get set for a normal interactive terminal.

Walter Roberson
Walter Roberson on 29 Jul 2011
Change the menu or icon so that the command for it is
$SHELL -l "matlab -desktop"
where you should probably replace $SHELL with the name of your preferred shell.

Estevan
Estevan on 1 Aug 2011
Thanks for your suggestion, but it doesn't work for me. Matlab doesn't launch at all after that change (and I tried various things, e.g. /bin/bash, with/without -l, -desktop, etc.)
Any other ideas?
Thanks!

Igor Izyurov
Igor Izyurov on 16 Aug 2021
10 years later another Matlab-on-Linux user [me] was having the same question.
I'm writing the answer for the history. The solution for any application is described here: https://askubuntu.com/questions/542152/desktop-file-with-bashrc-environment
In short, ~/.bashrc should be modified so, that all nessessary exporting occurs before these lines:
# Matlab, being run from Launcher won't see this:
export MATLABROOT=/usr/local/MATLAB/R2021a
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# But will see this:
export MATLABROOT=/usr/local/MATLAB/R2021a

Categories

Find more on Desktop in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!