我正在使用mex接口包装C ++代码。我在类型匹配方面遇到一些问题,实际上我未能将Matlab数组类型的输入转换为std :: vector类型,因为我的C ++代码需要它们。例如,我尝试使用mxGetPr [prhs [0]),但得到了
错误:从'double *'到'std :: vector'(aka>'vector')没有可行的转换
有什么方法可以在mex函数中解决此问题,而无需触碰我的C ++代码中的类型。非常感谢!
下面是代码的必需部分
#include "class_handle.hpp"
#include "RBergomiST.h"
#include "mex.h"
RBergomiST::RBergomiST() {
N = 0;
M = 0;
nDFT = 0;
par = ParamTot();
xC = new fftw_complex[0];
xHat = new fftw_complex[0];
yC = new fftw_complex[0];
yHat = new fftw_complex[0];
zC = new fftw_complex[0];
zHat = new fftw_complex[0];
}
RBergomiST::RBergomiST(double x, Vector HIn, Vector e, Vector r, Vector t,
Vector k, int NIn, long MIn){
N = NIn;
nDFT = 2 * N - 1;
M = MIn;
par = ParamTot(HIn, e, r, t, k, x);
xC = new fftw_complex[nDFT];
xHat = new fftw_complex[nDFT];
yC = new fftw_complex[nDFT];
yHat = new fftw_complex[nDFT];
zC = new fftw_complex[nDFT];
zHat = new fftw_complex[nDFT];
fPlanX = fftw_plan_dft_1d(nDFT, xC, xHat, FFTW_FORWARD,
FFTW_ESTIMATE);
fPlanY = fftw_plan_dft_1d(nDFT, yC, yHat, FFTW_FORWARD,
FFTW_ESTIMATE);
fPlanZ = fftw_plan_dft_1d(nDFT, zHat, zC, FFTW_BACKWARD,
FFTW_ESTIMATE);
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
// Get the command string
char cmd[64];
if (nrhs < 1 || mxGetString(prhs[0], cmd, sizeof(cmd)))
mexErrMsgTxt("First input should be a command string less than 64
characters long.");
// New
if (!strcmp("new", cmd)) {
// Check parameters
double x = mxGetScalar(prhs[0]);
Vector HIn= mxGetPr(prhs[1]);
Vector e= mxGetPr(prhs[2]);
Vector r= mxGetPr(prhs[3]);
Vector t= mxGetPr(prhs[4]);
Vector k= mxGetPr(prhs[5]);
int NIn;
long MIn;
if (nlhs != 1)
mexErrMsgTxt("New: One output expected.");
// Return a handle to a new C++ instance
plhs[0] = convertPtr2Mat<RBergomiST>(new RBergomiST(x, HIn, e, r, t,
k, NIn, MIn));
return;
}