mexFunction:mxDuplicateArray [英] mexFunction : mxDuplicateArray

查看:160
本文介绍了mexFunction:mxDuplicateArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用mxDuplicateArray函数时,遇到此错误:

When I used mxDuplicateArray function, I met this error:

无法将参数1转换为mxArray* mxDuplicateArray(const mxArray*)double*转换为const mxArray* {aka const mxArray_tag*}.

cannot convert double* to const mxArray* {aka const mxArray_tag*} for argument 1 to mxArray* mxDuplicateArray(const mxArray*).

有人知道如何解决吗?

这是我的代码的一部分:

This is part of my code:

    vector<int> *NNLt;
    double *NNLtout;
    Vector *V;
    Vector *Fb;
    mwSize *sn;
    mwSize nsn; 
    mwSize nf; 
    double hs;
    double bw;
    double mw; 
    mwSize ncols; 
    mwSize i;
    double *NNLtoutt;
...
       createNNLtriangle(NNLt, V, Fb, sn, nsn, nf, hs, bw, mw);    

       plhs[0] = mxCreateCellMatrix(nsn,50);
...
       for(i=0;i<nsn;i++){
//         copy(NNLt[i].begin(),NNLt[i].end(),NNLtout[i*50;i*50+NNLt[i].size()]);
//         NNLtoutt=mxCreatStrucMatrix(1,50,1,fnom);
           copy(NNLt[i].begin(),NNLt[i].end(),NNLtoutt);     
           mxSetCell(plhs[0],i,mxDuplicateArray(NNLtoutt));
       }

推荐答案

mxDuplicateArraymxArray指针作为输入,而不是double指针.

mxDuplicateArray takes an mxArray pointer as input, not a double pointer.

如果要将NNLt[i]向量复制到MATLAB矩阵中并将该矩阵放入单元格数组中,则可以执行以下操作:

If you want to copy your NNLt[i] vector into a MATLAB matrix and put that matrix into a cell array, you can do it like this:

for(...) {
  mxArray* tmp = mxCreatDoubleMatrix(1, NNLt[i].size(), mxREAL);
  copy(NNLt[i].begin(), NNLt[i].end(), mxGetPr(tmp));     
  mxSetCell(plhs[0], i, tmp);
}

您不应该尝试释放tmp矩阵,让MATLAB处理通过mx...函数分配的所有内存.

You should not try to free the tmp matrix, let MATLAB take care of any memory that you allocated through the mx... functions.

这篇关于mexFunction:mxDuplicateArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆