eye
Identity matrix.
Syntax
Section titled “Syntax”Y = eye % scalar 1Y = eye(n) % n×n identityY = eye(m, n) % m×n with 1s on the main diagonalY = eye(…, classname)Description
Section titled “Description”Returns an identity matrix — ones on the main diagonal, zeros elsewhere. Non-square shapes are allowed; the diagonal extends as far as the smaller dimension. The optional last string argument selects the element type.
Examples
Section titled “Examples”eye(3) % 3×3 identityeye(2, 4) % [1 0 0 0; 0 1 0 0]eye(3, 'int32') % int32 identity