S = speye(sz) returns a
matrix with ones on the main diagonal and zeros elsewhere. The size vector
sz defines size(S). For example, speye([2
3]) returns a 2-by-3 matrix.
S = speye(___,typename)
returns a sparse matrix of the specified data type. Specify the data type in addition to
any of the input argument combinations in previous syntaxes. (since R2025a)
Create a 1000-by-1000 square sparse identity matrix and view the sparsity pattern.
I = speye(1000);
spy(I)
The result is the same as sparse(eye(1000)), but this latter version requires temporary storage for the full representation before it is converted to sparse storage.
The speye function
supports GPU array input with these usage notes and limitations:
To run this function on a GPU and obtain a gpuArray output, use
any of these syntaxes:
S = gpuArray.speye.
S = gpuArray.speye(n).
S = gpuArray.speye(n,m).
S = gpuArray.speye(sz).
S =
gpuArray.speye(___,typename), where typename
specifies the data type in addition to the input argument combinations in any of
the previous syntaxes. (since R2025a)
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.