2014-01-28 158 views
1

我有一个调用matlab函数的小代码片段(保存在它自己的.m文件中)。用户可以选择要调用的matlab函数,它可能也可能不在MATLAB的默认文件夹(〜/ Documents/MATLAB)中。从C++调用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不会推出,但新的地址不会被添加到搜索路径。我在这里做错了什么?

我很感激帮助。

回答

1

你缺少第二封闭)

std::string addPathCommand = "/Applications/MATLAB_R2011b.app/bin/matlab -r \"addpath(genpath('"+ matlabFunctionPath + "'))\"";