我正在尝试使用一些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://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
}
};