/* \file MatlabMatrixToDoubleMatrix.cpp * \brief: convert a sparse or dense matlab matrix to a double* pointer */ #ifdef HAVE_CONFIG_H #include #else #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" #endif /*Matlab includes: */ #include "mex.h" #include "../../shared/shared.h" int MatlabMatrixToDoubleMatrix(double** pmatrix,int* pmatrix_rows,int* pmatrix_cols,const mxArray* mxmatrix){ int i,j,count,rows,cols; double *pmxdoublematrix = NULL; float *pmxsinglematrix = NULL; /*output: */ double* matrix=NULL; /*matlab indices: */ mwIndex* ir=NULL; mwIndex* jc=NULL; /*Ok, first check if we are dealing with a sparse or full matrix: */ if (mxIsSparse(mxmatrix)){ /*Dealing with sparse matrix: recover size first: */ pmxdoublematrix=(double*)mxGetPr(mxmatrix); rows=mxGetM(mxmatrix); cols=mxGetN(mxmatrix); if(rows*cols){ matrix=(double*)xcalloc(rows*cols,sizeof(double)); /*Now, get ir,jc and pr: */ ir=mxGetIr(mxmatrix); jc=mxGetJc(mxmatrix); /*Now, start inserting data into double* matrix: */ count=0; for(i=0;i