How can I set a custom path in Matlab R2017a on MacOS?

22 ビュー (過去 30 日間)
Povl Abrahamsen
Povl Abrahamsen 2017 年 7 月 4 日
コメント済み: Povl Abrahamsen 2020 年 10 月 8 日
I run Matlab on MacOS 10.12.5, with various useful programs installed in "non-standard" directories using Fink. With R2016b and earlier I added the line ". /sw/bin/init.sh" to the end of the ".matlab7rc.sh" file in my home directory, to add these paths to the Matlab command line. That script, which is part of Fink, prepends "/sw/bin" and a couple of other directories to the search path (environment variable $PATH); the result in R2016b is:
>> !echo $PATH
/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
However, this doesn't seem to work in R2017a; the only directories in Matlab's search path are /usr/bin, /usr/sbin, and /sbin. How can I get Matlab to look in other directories?

採用された回答

Royi Avital
Royi Avital 2020 年 10 月 8 日
You should use setenv() to set the path.
Pay attention that usually you want to add something to the path and not override it. Hence do something like:
PATH_SEP = pathsep();
myDir = '/some/dir/in/my/mac/';
currPath = getenv('PATH');
setenv('PATH', [currPath, PATH_SEP, myDir]);
Of course this is the MATLAB way. You could also just use system command:
!export PATH=$PATH:/my/path
  1 件のコメント
Povl Abrahamsen
Povl Abrahamsen 2020 年 10 月 8 日
Thank you very much!
This solution worked, when I added the code to /Applications/MATLAB_R2020a.app/toolbox/local/matlabrc.m

サインインしてコメントする。

その他の回答 (1 件)

Shashank
Shashank 2017 年 7 月 11 日
編集済み: Shashank 2017 年 7 月 11 日
Hi Poul,
You can try using a startup.m File
The startup.m file is for specifying startup options. You can add folders to the search path by including addpath statements in a startup.m file. For example, to add the specified folder, /home/username/mytools to the search path at startup, include this statement in a startup.m file:
addpath /home/username/mytools
- Shashank
  1 件のコメント
Povl Abrahamsen
Povl Abrahamsen 2017 年 7 月 11 日
This question is about paths for running command line programs, not Matlab scripts. So "addpath" is not relevant.

サインインしてコメントする。

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by