【发布时间】:2014-01-28 01:04:10
【问题描述】:
我有一个小代码 sn-p 调用一个 matlab 函数(保存在它自己的 .m 文件中)。用户可以选择调用 matlab 函数,它可能在也可能不在 MATLAB 的默认文件夹(~/Documents/MATLAB)中。
如果它不在默认搜索路径中,我想将函数的包含文件夹添加到 MATLAB 的搜索路径中。当我尝试使用终端(我在 MAC 上)执行此操作时,使用以下命令:
/Applications/MATLAB_R2011b.app/bin/matlab -r "addpath(genpath('/Folder/Address/Here'))"
MATLAB 启动,我可以看到新地址已成功添加到搜索路径中。
但是,当我尝试使用以下命令通过 C++ 程序运行此命令时:
std::string matlabFunctionPath = "/Folder/Address/Here"
std::string addPathCommand = "/Applications/MATLAB_R2011b.app/bin/matlab -r \"addpath(genpath('"+ matlabFunctionPath + "')\"";
::popen(shellCommand.c_str(), "r"));
MATLAB 确实启动了,但新地址没有添加到搜索路径中。我在这里做错了什么?
感谢您的帮助。
【问题讨论】: