how to create a diagonal matrix in matlab code example Example: finding diagonal elements in matlab D = diag(v)