MATLAB: Matrix Elements Manipulation Using Matlab

matrixmatrix manipulation

I have four matrices A, B, C and D of dimension: A=4×4; B=4×3; C=3×4; D=3×3.
A=[A11 A12 A13 A14 ;
A21 A22 A23 A24 ;
A31 A32 A33 A34 ;
A41 A42 A43 A44 ];
Elements of A matrix (like A11, A12 …) with the indexing are shown. The other matrices also have the elements in a similar fashion (like B11, B12, …for the B-Matrix and it applies to other remaining matrices).
Problem: I want to construct a bigger matrix of dimension 7x7 from it in the following way:
1. Place B11 in between A11 and A12; B12 in between A12 and A13 and so on.
2. Place C11 in between A11 and A21; C12 in between A12 and A22 and so on.
3. Place D11 in between C11 and C12; D12 in between C12 and C13 and so on.
Finally the matrix should look like:
H=[ A11 B11 A12 B12 A13 B13 A14;
C11 D11 C12 D12 C13 D13 C14;
A21 B21 A22 B22 A23 B23 A24;
C21 D21 C22 D22 C23 D23 C24;
A31 B31 A32 B32 A33 B33 A34;
C31 D31 C32 D32 C33 D33 C34;
A41 B41 A42 B42 A43 B43 A44];
I would be very grateful if anybody helps me in implementing the same using Matlab command.
Thanking You!

Best Answer

a=zeros(4,7);
a(:,1:2:end)=A;
a(:,2:2:end)=B;
b=zeros(3,7);
b(:,1:2:end)=C;
b(:,2:2:end)=D;
out=zeros(7);
out(1:2:end,:)=a;
out(2:2:end,:)=b