Why do I receive an an "out of memory" error when I resize a sparse matrix in a MEX file in MATLAB?

Illustration
Mackenzie - 2020-09-25T10:17:13+00:00
Question: Why do I receive an an "out of memory" error when I resize a sparse matrix in a MEX file in MATLAB?

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.

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

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.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!