# Extracting Elements of a Matrix of Matrices to Create two separate Matrices

I have a vector, twith 2 elements and a 3x4 matrix A. I intend adding each element in t to each element Ato generate 2 separate matrices BB and CC. My attempt generated a matrix of matrices, AA. How do I extract the elements of AA to obtain independent BB and CC? Or is there a better way of doing this without generating a matrix of matrices?.

n = 3;
A = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
t = {x, y};
AA = BB = CC = Table[0, {i, 1, n}, {j, 1, n + 1}];

Do[AA[[i, j]] = A[[i, j]] + t, {i, 1, n}, {j, 1, n + 1}]

"Result Intended"
BB = {{1 + x, 2 + x, 3 + x, 4 + x}, {5 + x, 6 + x, 7 + x, 8 + x}, {9 + x, 10 + x, 11 + x, 12 + x}} // MatrixForm
CC = {{1 + y, 2 + y, 3 + y, 4 + y}, {5 + y, 6 + y, 7 + y, 8 + y}, {9 + y, 10 + y, 11 + y, 12 + y}} // MatrixForm

"Result Obtained"
AA={{{1 + x, 1 + y}, {2 + x, 2 + y}, {3 + x, 3 + y}, {4 + x, 4 + y}}, {{5 + x, 5 + y}, {6 + x, 6 + y}, {7 + x, 7 + y}, {8 + x, 8 + y}}, {{9 + x, 9 + y}, {10 + x, 10 + y}, {11 + x, 11 + y}, {12 + x, 12 + y}}}//MatrixForm


aA = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
{BB, CC} = {x + aA, y + aA}


{{{1 + x, 2 + x, 3 + x, 4 + x}, {5 + x, 6 + x, 7 + x, 8 + x}, {9 + x, 10 + x, 11 + x, 12 + x}},
{{1 + y, 2 + y, 3 + y, 4 + y}, {5 + y, 6 + y, 7 + y, 8 + y}, {9 + y, 10 + y, 11 + y, 12 + y}}}

Or with t = {x, y};

{BB, CC} = aA + # & /@ t


same result

• At kglr. Thank you for providing such a neat way of getting the desired result! I will adopt this approach to solving the actual problem I was working on. On the other hand, I was wondering if extracting the matrices from the matrix of matrices is also possible. I do run into such set up from time to time. Thank you! – D. Andrew Jan 19 '18 at 14:21
• @D.Andrew, my pleasure. Thank you for the accept. Re "extracting the matrices from the matrix of matrices", can you provide an example? – kglr Jan 19 '18 at 15:45