v = rem(1:10, 2);
M = 10 + 10 * (v ~= v.')
Or with linear indexing:
M = 10 * ones(9);
M(2:numel(M)) = 20;
The 1st method works with all sizes of the matrox, while the 2nd method needs an odd number of rows, so it does not work with n=10.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!