Returns a one-dimensional matrix containing one of a matrix's diagonals. The diagonal returned starts in the upper-left corner and ends in the lower-right corner. This will cause a Dimension Error unless the matrix is a square matrix.

:diag(one-dimensional matrix)

This returns a matrix that has the specified diagonal, and contains zeros in all other positions.


  • diag([1,2,3;4,5,6;7,8,9]) returns [[1,5,9]].
    Diag( with highlight
  • diag([[1,4]]) returns [[1,0][0,4]]

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.