MATLAB Answers


setenv fails to change environment variables on Linux

Asked by Arabarra on 13 Mar 2019
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
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
although Matlab finds the correct value through getenv:
>> getenv('PATH')
ans =
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,
matlab version: (R2018a)


Sign in to comment.

0 Answers