# What is the format of saving sparse matrix in MATLAB?

We know that for lagre sparse matrices, we can use compressed sparse row (CSR) or compressed sparse column (CSC) format to store the sparse matrices so that we can save CPU memory. And the coordinate format (COO) does not save memory.

My question is that in MATLAB, a sparse matrix $$A$$ can be indexed for example, A(1,2), so is COO format for sparse matrix used in MATLAB? Because COO is not cheap, MATLAB instead is an optimal software, I think matlab must have considered this issue. How is MATLAB store the sparse matrix? Thanks very much.

Matlab internally uses compressed sparse column (CSC) format for sparse matrices. The design and implementation of Matlab's sparse matrices are described in this document. As a consequence of using CSC format, indexing into sparse matrices can be an expensive operation. This is discussed in the help pages on sparse matrices.

• Thanks Professor, I get it. No wonder MATLAB editor often reminds me of some warnings that when I used indexing way to use an entry of a sparse matrix in a MATLAB for loop. It said that indexing way of sparse matrix is too slow to run. Since matlab uses CSC way to store sparse matrix, why can we use inedexing way to use an element of a sparse matrix, e.g., A(2,2)=1? Is there some principles in matlab interior, and matlab just give us a friendly way to use sparse matrix as the way of full matrix? Thanks very much. – sunshine Nov 3 '19 at 0:52
• Yes, that is exactly right. If you index into a sparse matrix, Matlab will perform the necessary CSC operations under the hood to make it work. This way, they provide a user-friendly (but slow) interface for modifying and creating sparse matrices. – Will P. Nov 3 '19 at 7:10