フィルターのクリア

Accessing shell environment variables in MATLAB under Ubuntu Linux 10.04

6 ビュー (過去 30 日間)
Estevan
Estevan 2011 年 7 月 29 日
回答済み: Ty Watkins 2022 年 1 月 21 日
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.

回答 (4 件)

Ty Watkins
Ty Watkins 2022 年 1 月 21 日
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 2011 年 7 月 29 日
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 2011 年 8 月 1 日
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 2021 年 8 月 16 日
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

カテゴリ

Help Center および File ExchangeDesktop についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by