MATLAB: Trouble with a command in MATLAB’s system()

mac osMATLABsystemwhich

I'm having trouble with MATLAB's system() command on Mac OS High Safari. When I run 'which python3' in system(), I get this output:
>> [status, result] = system('which python3')
status =
1
result =
0×0 empty char array
However, when I run the same command on the same computer in Mac OS terminal, I get a better output:
$ which python3
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
On the other hand, 'which python' works fine in both MATLAB's system() and in the Mac OS terminal. When invoked in MATLAB system():
>> [status, result] = system('which python')
status =
0
result =
'/usr/bin/python
'
When invoked in Mac OS terminal, I get a similar result:
$ which python
/opt/local/bin/python
Can anyone help explain why I'm having trouble with "system('which python3')"?
Thanks in advance for your help.

Best Answer

MATLAB typically is launched as a graphics program by the operating systems. Such programs do not execute the user's login scripts, so environment variables are not set to user login values: they stay at the system defaults.
system() does not run scripts in a "login" context, so profile variables are not set up either.
The only thing that executes are the scripts that are run every time a shell is initialized.
Related Question