This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

Full and Sparse Matrices


It is not uncommon to have matrices with a large number of zero-valued elements and, because the MATLAB® software stores zeros in the same way it stores any other numeric value, these elements can use memory space unnecessarily and can sometimes require extra computing time.

Sparse matrices provide a way to store data that has a large percentage of zero elements more efficiently. While full matrices internally store every element in memory regardless of value, sparse matrices store only the nonzero elements and their row indices. Using sparse matrices can significantly reduce the amount of memory required for data storage.

You can create sparse matrices for the double and logical classes. All MATLAB built-in arithmetic, logical, and indexing operations can be applied to sparse matrices, or to mixtures of sparse and full matrices. Operations on sparse matrices return sparse matrices and operations on full matrices return full matrices.

For more information about the computational advantages and construction of sparse matrices, see Memory Management and Creating Sparse Matrices.

Sparse Matrix Functions

This table shows some of the functions most commonly used when working with sparse matrices.




Convert a sparse matrix to a full matrix.


Determine if a matrix is sparse.


Return the number of nonzero matrix elements.


Return the nonzero elements of a matrix.


Return the amount of storage allocated for nonzero elements.


Allocate space for a sparse matrix.


Create a sparse matrix or convert full to sparse.


Create a sparse identity matrix.


Create a sparse uniformly distributed random matrix.

Was this topic helpful?