matlab put diagonal elements with a square matrix code example Example: finding diagonal elements in matlab D = diag(v)