MATLAB: How to create triangle inside matrix

code solutioncuriousMATLABsoftware

What if I wanted a triangle of numbers from the formula (2n-1) that resulted in a triangle inside a matrix such that…
[0 0 0 0 1 0 0 0 0]
0 0 0 2 1 2 0 0 0
0 0 3 2 1 2 3 0 0
0 4 3 2 1 2 3 4 0]
etc?…

Best Answer

sort(spdiags(toeplitz(1:n)))