My original objective was to reduce the Cody size as much as possible. You can make this solution general by using y = discretize(spiral(n), [0 1:2:n].^2+.5) or y = discretize(spiral(n), [0 1:2:n].^2, 'IncludedEdge','right'), which has a higher size though.

more elegant solution than a loop: Use the LDL decomposition on the bullseye matrix and you will find an interesting L and D matrix. THe D matrix is diagonale and can be built using n only. THe matrix L is the sum of a lower triangular matrix whose lowest part is put to zero using the mirrored triangular matrix. Finally the identity matrix is added :)