MATLAB: How to make this following matrix

Actualy this question related with my question before matlabcentral/answers/47516-how-can-make-code-to-present-this-following-case. Although I just add one matrix C but i cannot to solve this case. so any one help me please.
I am doing my research. I have problem to make code to present this following matrices.
A(:,:,1)=[ 1 2 3 4;
3 2 1 4]
A(:,:,2)=[ 1 3 4 2;
4 2 1 3]
C(:,:,1)=[ 0 0 1 2;
1 1 1 0]
C(:,:,2)=[ 1 0 1 0;
0 1 1 1]
Matrices C is matrices that show how many zeros before value of element matrix A in matrix result..
And i have this following matrices to present value in matrices A.
value=1,
B(1)=[1 1 1;
1 1 1]
value=2,
B(2)=[2 2 2;
2 2 2]
value=3,
B(3)=[3 3 3;
4 4 4]
value=4,
B(4)=[4 4 4;
3 3 3]
So that I will get this following matrices by combining A and C.
Res(:,:,1)=[1 1 1 2 2 2 0 3 3 3 0 0 4 4 4;
1 1 1 2 2 2 0 4 4 4 0 0 3 3 3;
0 3 3 3 0 2 2 2 0 1 1 1 4 4 4;
0 4 4 4 0 2 2 2 0 1 1 1 3 3 3]
Res(:,:,2)=[0 1 1 1 3 3 3 0 4 4 4 2 2 2 0;
0 1 1 1 4 4 4 0 3 3 3 2 2 2 0;
4 4 4 0 2 2 2 0 1 1 1 0 3 3 3;
3 3 3 0 2 2 2 0 1 1 1 0 4 4 4]
thanks for your help

Best Answer

A = [1 2 3 4;3 2 1 4]
B{1} = [1 1 1;1 1 1];
B{2} = [2 2 2;2 2 2];
B{3} = [3 3 3;4 4 4];
B{4} = [4 4 4;3 3 3];
C = [0 0 1 2;1 1 1 0];
C = mat2cell(C,ones(size(C,1),1),ones(size(C,2),1));
D = B(A);
E = cell2mat(cellfun(@(x,n) [zeros(size(x,1),n) x], D, C,'UniformOutput',false))