Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

c++ - mexFunction : mxDuplicateArray

When I used mxDuplicateArray function, I met this error:

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

Is there anyone who knows how to fix it?

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));
       }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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);
}

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...