如何将参数(argc,argv)从C ++代码传递到MatLab Mex文件?

问题描述 投票:1回答:1

我正在尝试使用一些C ++代码并在其周围放置适当的MatLab mex函数包装器,以便我可以将我的C ++称为MatLab函数。我的C ++代码使用argc和argv接受4个命令行参数。

命令行中的C ++函数调用将是:myfunciton string1 string2 string3 string4

我想要的是来自MatLab命令行的MatLab函数调用,如:myfunction('string1','string2','string3','string4')

我查看了以下博客文章,OP可以使用c(而不是c ++)来实现这一点,在它和​​C ++的MatLab文档之间我有点困惑(主要归因于Blog Post之间的语法差异)和c ++的Mathwork文档)

https://sungkwang.wordpress.com/2011/01/17/passing-argument-in-mex-function-without-modifying-c-code/

https://www.mathworks.com/help/matlab/matlab_external/c-mex-source-file.html

#include "mex.hpp"
#include "mexAdapter.hpp"

using namespace matlab::data;
using matlab::mex::ArgumentList;

class MexFunction : public matlab::mex::Function {
public:
    void operator()(ArgumentList outputs, ArgumentList inputs) {
       int argc = 0;
       argc = inputs.size();
       //I'm unsure of how to handle the argv portion(?)
       main(argc,argv);

    }


    int main(int argc, char *argv[]){
       //Rest of code... omitted for brevity of question
    }
};

c++ matlab mex argv argc
1个回答
0
投票

将其复制到命令窗口:

edit([matlabroot '/extern/examples/cpp_mex/arrayProduct.cpp']);

你可以找到一些其他的例子here

© www.soinside.com 2019 - 2024. All rights reserved.