First, this line is incorrect:
A=(double **) mxCalloc( M, sizeof(double));
It should be one of the following instead:
A=(double **) mxCalloc( M, sizeof(*A)); // I prefer this one
or
A=(double **) mxCalloc( M, sizeof(double *));
But the answer to your real question will depend on what you are doing with the sparse matrix downstream in your code. Your "full" code creates a potentially non-contiguous matrix using an "array" of pointers. All of the double values are 0. The "sparse" code you show does the equivalent ... it creates a matrix of the same size where all the double values are 0 (assuming m==M and n==N and nz=something_reasonable). So you already have code that creates the sparse version of the full 0's matrix, as long as you assign it to a variable. E.g.,
mxArray *ms;
ms = mxCreateSparse(m,n,nz,mxREAL);
My guess is you need to fill in the non-zero values of the sparse matrix? If so, please provide more detail about what you are doing and where these non-zero values are located within the sparse matrix and then we can discuss how to code that (e.g., modifying the Pr and Ir and Jc data).