0

I've installed a series of binaries which appear in usr/local/bin on my MACOSX (They're called DCMTK). The usr/local/bin folder appears on the path as expected:

PATH=/Users/jim/Library/Enthought/Canopy_64bit/User/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:niftyreg_install/bin

I can run these commands as expected from any folder in a Terminal window, however I can't seem to run any of them from within Matlab (2014b) using the command:

cmd=['dcmdump -h'];
system(cmd)
/bin/bash: dcmdump: command not found

Running 'env' in a Terminal shows that I am using the same SHELL as Matlab:

SHELL=/bin/bash

My question is why is it when Matlab invokes bin/bash it is not finding the binaries in usr/local/bin? Is there something in .bash_profile I need to update?

Thanks,

Jim

4
  • Try echoing your PATH from within Matlab itself... cmd=['echo $PATH']; system(cmd); Commented Apr 2, 2015 at 10:55
  • 'cmd=['echo $PATH']; system(cmd); /usr/bin:/bin:/usr/sbin:/sbin' You hit the nail on the head Mark, usr/bin/local is not in there! Any chance you could tell me how I would add it? How come there is this discrepancy? Commented Apr 2, 2015 at 11:26
  • I'm sorry, I don't. I was just trying to help you work it out. I am sure someone else will be able to assist now the problem is a little clearer. Good luck! Commented Apr 2, 2015 at 11:30
  • Thanks for your help in identifying the problem @MarkSetchell, the line below from the poster managed to add the single line required. Still not sure why there is a discrepancy between PATH asked through MATLAB and through terminal, but a solution has been found! Commented Apr 2, 2015 at 13:11

1 Answer 1

1

As Mark Setchell already pointed out in his comments, you can echo the PATH variable from within MATLAB using

cmd=['echo $PATH'];
system(cmd);

You can also get environment variables, such as $PATH using the MATLAB getenv function:

getenv('PATH');

As you also posted in comments, in your case /usr/bin/local is missing in the $PATH variable. MATLAB has an option to set environment variables via the setenv function. But watch out: This sets the variable to only the specified value. To append a folder, you have to query the existing variable and append a folder to that:

setenv('PATH', [getenv('PATH'),':','/usr/bin/local']);

As separator, either ; (for Windows systems) or : (for Unix based systems) is used. In the example above I added : as you are working with Mac OS X.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi @hbaderts, Thank you very much for your suggestion - this worked absolutely perfectly! Very grateful for your solution. Just as an aside - would you know why querying the PATH through MATLAB would give a different list from that done in a terminal? I though the whole point would be that it should be the same. Jim
Hi Jim, I do not know why and how exactly this works on Mac, but the PATH of the Terminal and other programs are not identical. If you start MATLAB from the Terminal, then it has the same PATH as the Terminal itself. When you start the application as usual, then the PATH is somehow different.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.