【问题标题】:Call a Matlab function from c++从 C++ 调用 Matlab 函数
【发布时间】: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 确实启动了,但新地址没有添加到搜索路径中。我在这里做错了什么?

感谢您的帮助。

【问题讨论】:

    标签: c++ matlab shell


    【解决方案1】:

    你错过了第二个结束)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-31
      • 1970-01-01
      • 2015-04-08
      • 2010-12-15
      • 1970-01-01
      相关资源
      最近更新 更多