I want to create a new sparse matrix and pass the value of the input sparse matrix to it, and then call mexCallMATLAB to get its transpose. The code crashed,
#include <stdio.h>#include <stdlib.h>#include <mex.h>#include <math.h>#include <time.h>#include <string.h>extern void mexFunction(int iNbOut, mxArray *pmxOut[], int iNbIn, const mxArray *pmxIn[]){ mxArray *A, *B; double *d,*p,*pin,*out; mwSize m,n,nzmax; mwIndex *ir, *jc; m = mxGetM(pmxIn[0]); n = mxGetN(pmxIn[0]); nzmax = mxGetNzmax(pmxIn[0]); ir = mxGetIr(pmxIn[0]); jc = mxGetJc(pmxIn[0]); pin = mxGetPr(pmxIn[0]); A = mxCreateSparse(m, n, nzmax, mxREAL); mxSetIr(A, ir); mxSetJc(A, jc); mxSetPr(A, pin); d = mxGetPr(A); B = mxCreateSparse(m, n, nzmax, mxREAL); mexCallMATLAB(1, &B, 1, &A, "transpose"); p = mxGetPr(B); pmxOut[0] = mxCreateNumericArray(1 , nzmax, mxSINGLE_CLASS,mxREAL); out = mxGetPr(pmxOut[0]); for(mwSize i = 0; i < nzmax; i++) { out[i] = p[i]; mexPrintf("pmxOut = %f", out[i]); }}
Best Answer