MATLAB Answers

0

setenv fails to change environment variables on Linux

Asked by Arabarra on 13 Mar 2019
Hi,
I'm using Matlab on Ubuntu 16.04, and it seems that Matlab cannot run system calls:, because of an apparently failure of the Matlab command setenv to change the environment variables in the shell running below my Matlab session. To clarify what I mean, I copy and paste from my current session in Matlab:
>> ls /usr/local/bin/chimera
/usr/local/bin/chimera
This file /usr/local/bin/chimera is an executable that I would like to run from matlab without needing to pass the full path (i.e., as !chimera or system('chimera');). To make it visible to my Matlab session, I prepend it to the environment variable PATH of the linux shell through the matlab commands getenv and setenv
>> setenv('PATH',['/usr/local/bin/:',getenv('PATH')]);
However, the Linux shell cannot find the executable "chimera" when asked by Matlab:
>> !which chimera
>>
In fact, looks like the PATH variable was never changed from the point of view of the Linux Shell
>> !echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.
although Matlab finds the correct value through getenv:
>> getenv('PATH')
ans =
:/usr/local/bin/chimera:/usr/local/bsse/MATLAB_R2018a/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/opt/puppetlabs/bin:'
In any case, this does not help me, as my Matlab session is unable to run system calls properly:
>> unix('chimera');
/bin/bash: chimera: command not found
>> system('chimera');
/bin/bash: chimera: command not found
So, what can be the reason that setenv is not working properly?
thanks in advance,
Daniel
matlab version: (R2018a)

  0 Comments

Sign in to comment.

0 Answers