Calling programs (AMPL) from within Matlab on a Mac

2 ビュー (過去 30 日間)
Josh
Josh 2011 年 8 月 11 日
Greetings, I just switched to a Mac, and am trying to call another program from within Matlab (in this case AMPL). I think my problem is simple: I want to call AMPL from a Matlab script. On a Windows computer I used the command
strAmplSystemCall = sprintf('ampl AC.run'); system(strAmplSystemCall);
(ampl is in the Matlab path). On the mac, I'm now getting the error
/bin/bash: ampl: command not found
I've tried it with './ampl' instead of just 'ampl' as well, and received the same error (with ./ampl not found). Anyone know the right syntax for this?
Josh

回答 (1 件)

Chirag Gupta
Chirag Gupta 2011 年 8 月 11 日
I guess, when you run ampl, you would need certain directories to be on the PATH (environment variable) as well as some dynamic libraries (DYLD_LIBRARY_PATH another env).
Try setting the environment variables before calling the system command. You should be able to do so using export command in the bash or using setenv directly from MATLAB
  3 件のコメント
Walter Roberson
Walter Roberson 2011 年 8 月 11 日
oldLP = getenv('DYLD_LIBRARY_PATH');
newLP = oldLP;
if ~isempty(newLP); newLP(end+1) = ':'; end
newLP = [newLP, 'TheAdditionalPath'];
setenv('DYLD_LIBRARY_PATH',newLP);
Josh
Josh 2011 年 8 月 12 日
Thanks - I tried this, plus the instructions for adding the directory to the PATH (http://www.mathworks.com/help/techdoc/matlab_env/f0-12994.html#f0-38522). Unfortunately no success yet - I can use AMPL within the folder the program is in (can't move it around unfortunately due to licensing), but this is not nearly as convenient as being able to call it from anywhere.

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

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by