MATLAB: Creating an 8×8 matrix using “diag”

helpMATLABmatrix

So im trying to create an 8×8 matrix with 2's in the diagonal but 0s everywhere else. I used diag(8,8)*0 + 2 but that gived me 2's everywhere.

Best Answer

2*eye(8)
Related Question