MATLAB: N number of 2×2 matricies to diagonal matrix

2x2arraydiagonalmatrix

I have a 2×2 matrix that I need put into the diagonal of a matrix n times. In other words, on each diagonal, a new 2×2 matrix prints. For cells with two k values, they should be added together.
For example:
n = 3:
k -k 0 0
-k k+k -k 0
0 -k k+k -k
0 0 -k k
What I have:
n = input('Input the number of elements:');
k = ((E * avg_area)/L)*[+1 -1; -1 +1];
for n;
k_global = diag(k);
end

Best Answer

n = input('Input the number of elements:');
k = ((E * avg_area)/L);
k_global=diag([k,repmat(k+k,1,n-1),k])+diag(repmat(-k,1,n),-1)+diag(repmat(-k,1,n),1);