问题
When I used mxDuplicateArray
function, I met this error:
cannot convert
double*
toconst mxArray* {aka const mxArray_tag*}
for argument1
tomxArray* 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));
}
回答1:
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.
来源:https://stackoverflow.com/questions/51622228/mexfunction-mxduplicatearray