Skip to content

eye

Identity matrix.

Y = eye % scalar 1
Y = eye(n) % n×n identity
Y = eye(m, n) % m×n with 1s on the main diagonal
Y = eye(…, classname)

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.

eye(3) % 3×3 identity
eye(2, 4) % [1 0 0 0; 0 1 0 0]
eye(3, 'int32') % int32 identity
  • zeros — Array of all zeros.
  • ones — Array of all ones.