diag(A) returns the diagonal elements of a matrix A. diag(x) puts the vector x on the diagonal of a zero matrix.