speye
Sparse identity matrix.
Syntax
Section titled “Syntax”S = speye(n)S = speye(m, n)Description
Section titled “Description”Returns a sparse identity matrix — n × n square or m × n rectangular with ones on the main diagonal and zeros elsewhere. Equivalent to sparse(eye(...)) but builds in sparse storage from the start (much cheaper for large n).
Examples
Section titled “Examples”speye(1000) % 1000×1000 sparse identityspeye(3, 5) % 3×5 with ones on the main diagonal