MATLAB: Tridiagonal Matrix with subdiagonal and main diagonal is also matrix

tridiagonal

I have two matrices A and B. I want A to be main diagonal and B to be my subdiagonals. How do I create such a matrix? By the way sizes of A and B changes but they are square matrices.
Specifically, a1=4,b1=-1
A =diag(a1*ones(1,N-1)) + diag(b1*ones(1,N-2),1) + diag(b1*ones(1,N-2),-1)
B=(-1)*eye(N-1)
These are my A and B matrices. I need to define a (N-1)*(N-1) times (N-1)*(N-1) matrix . For example for N=1000 or N=5000 I should be able to change the N value.

Best Answer

So, you want a block Toeplitz matrix?
N = 5;
A =diag([7 4 4]);
B=[8 8 10; 2 5 2; 10 8 7];
C=zeros(3);
blocks={C,B,A};
result=cell2mat(blocks( toeplitz(1+[2,1,zeros(1,N-2)]) ))
result = 15×15
7 0 0 8 8 10 0 0 0 0 0 0 0 0 0 0 4 0 2 5 2 0 0 0 0 0 0 0 0 0 0 0 4 10 8 7 0 0 0 0 0 0 0 0 0 8 8 10 7 0 0 8 8 10 0 0 0 0 0 0 2 5 2 0 4 0 2 5 2 0 0 0 0 0 0 10 8 7 0 0 4 10 8 7 0 0 0 0 0 0 0 0 0 8 8 10 7 0 0 8 8 10 0 0 0 0 0 0 2 5 2 0 4 0 2 5 2 0 0 0 0 0 0 10 8 7 0 0 4 10 8 7 0 0 0 0 0 0 0 0 0 8 8 10 7 0 0 8 8 10