MATLAB: Hi, can someone help me generate a square matrix with all its elements one, exept its diagonal? As the following

diagonalones

ans = 2 1 1 1 1 3 1 1 1 1 4 1 1 1 1 5

Best Answer

A suggestion:
M = diag(1:4)+1