I think this should be very simple (Writing the generalized matrix in the image). You just need to know array indexing and for loop in MATLAB.
Take as input, a k vector, and a constant n.
Create a nxn zeros-only-matrix A with the help of zeros function.
For n>=3, loop through i= 2 to n-1, and update the matrix values according to the values in the image (you will need to write just 3 assgnment statements inside the for loop for the three values). For i=1 and i=n update the matrix values outside the loop (total 4 assignment statement).
For n<3, you can update the values in the matrix without loop.
Please first try yourself and then post your doubts here.