mxCreateSparse returning an empty matrix

13 Ansichten (letzte 30 Tage)
Jagvaral
Jagvaral am 26 Sep. 2013
Bearbeitet: Jagvaral am 26 Sep. 2013
Hello I want to create a sparse matrix in c/mex and use it in matlab but I have a problem with mxCreateSparse function. I wrote the below code in c and called it from matlab. But it is creating a 4x2 zeros sparse. I don't know why it is happening. And, When I tried to open that empty sparse matrix, Matlab crashed immediately. Please help me to identify the error. Thanks in advance.
#include <math.h>
#include <stdlib.h>
#include "mex.h"
#include "matrix.h"
#include <stdio.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
double Ap[4] = {5.8, 6.2, 5.9, 6.1}, *cAp;
int Ai[4] = {0, 2, 1, 3}, *cAi ;
int Ax[3] = {0, 2, 4}, *cAx ;
mxArray *pargout;
pargout = mxCreateSparse (4, 2, 4, mxREAL) ;
cAp = (double *)mxGetPr(pargout);
memcpy(cAp, Ap, 4*sizeof(double));
cAi = (int *)mxGetIr(pargout);
memcpy(cAi, Ai, 4*sizeof(int));
cAx = (int *)mxGetJc (pargout) ;
memcpy(cAx, Ax, 4*sizeof(int));
plhs[0] = pargout;
}

Antworten (0)

Kategorien

Mehr zu C Matrix API finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by