This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Sparse identity matrix


S = speye(m,n)
S = speye([m n])
S = speye(n)
S = speye


S = speye(m,n) and S = speye([m n]) form an m-by-n sparse matrix with 1s on the main diagonal.

S = speye(n) abbreviates speye(n,n).

S = speye returns the sparse form of the 1-by-1 identity matrix.


I = speye(1000) forms the sparse representation of the 1000-by-1000 identity matrix, which requires only about 16 kilobytes of storage. This is the same final result as I = sparse(eye(1000,1000)), but the latter requires eight megabytes for temporary storage for the full representation.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a