There are many ways of doing most anything in a tool like MATLAB.
To create the matrix you want to create, the very simplest one liner to do so is...
s = 9*~eye(3)
0 9 9
9 0 9
9 9 0
Clearly this relies on the fact that your matrix was a very simple one, with constant off-diagonal elements, as well as constant (but different) diagonal elements. But the general idea is one that will work in other places too, so it is good to remember.
You did find a very reasonable way to zero out the diagonal of a matrix, or indeed to replace it too. I'll replace the diagonal of a 3x3 matrix of 9's with the numbers [1,2,3], just to show that you can use it for any general vector of elements.
s = 9*ones(3);
s(logical(eye(3))) = 1:3
1 9 9
9 2 9
9 9 3
(Of course, vote for this answer if you found it useful.)