MATLAB: Do I receive an an “out of memory” error when I resize a sparse matrix in a MEX file in MATLAB

MATLABmatrixmemorymexmex fileofoutresizesparse

Why do I receive an "out of memory" error when I resize a sparse matrix in a MEX-file in MATLAB?
I wrote a MEX-file that handles sparse matrices correctly. When the DLL returns the output data to the MATLAB workspace, the matrix is correct. I use the FIND function on this output matrix and can read out columns and rows. However, if the matrix contains less non-zero values, I get an OUT OF MEMORY error.

Best Answer

The problem appears to occur when you incorrectly size the JC field of a sparse matrix. This field must be size N+1, where N is the length of the number of columns of the sparse matrix.