You can also use [`SparseArray`](https://reference.wolfram.com/language/ref/SparseArray.html) as follows

    sa[n_] := SparseArray[{{i_, i_} /; i > 1 -> 1 - i, {i_, j_} /; 1 < i < j ->  0}, {n, n}, 1]

    matrix2 = sa[7] 
    matrix2 == matrix
>   True