Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...