Error in using mldivide in mex
Mostrar comentarios más antiguos
I am trying to use mldivide inside mex. The below code is simply trying to solve Ax=b, for r=5, where A is 5*5 Identity and b=0:1:4. So mldivide should output x=0:1:4. Instead I am getting all 0's as output vector. Can anyone see the mistake in the code?
Thanks
A=lsm, b=lsv and x=lss in the code below.
#include "mex.h"
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mwIndex l, k;
double *lsm, *lsv, *lss;
mxArray *Lsmatrix[2];
int r;
r=*((double *)mxGetPr(prhs[0]));
plhs[0]=mxCreateDoubleMatrix(r, 1, mxREAL);
lss=mxGetPr(plhs[0]);
Lsmatrix[0]=mxCreateDoubleMatrix(r, r, mxREAL);
Lsmatrix[1]=mxCreateDoubleMatrix(r, 1, mxREAL);
lsm=mxGetPr(Lsmatrix[0]);
lsv=mxGetPr(Lsmatrix[1]);
for(l=0; l<r;l++){
for(k=0;k<r;k++){
lsm[k+l*r]=0;
if(l==k){
lsm[k+l*r]=1;
}
}
lsv[l]=l;
}
mexCallMATLAB(1, lss, 2, &Lsmatrix , "mldivide");
}
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!