# Entering block matrices, general case doesn't work

I want to enter several matrices at different positions in blocks. There is already a very similar answer here: https://mathematica.stackexchange.com/a/3562/6138

I thought that simply generalizing this function, would yield the correct result. But something seems not to work.

This is my function:

fmetmat[A_?MatrixQ, C_?MatrixQ, D_?MatrixQ, pos_] :=
SparseArraySparseBlockMatrix[{{1, 1} -> A, {1 + pos, 1} ->
Transpose[C], {1, 1 + pos} -> C, {1 + pos, 1 + pos} -> D},
Dimensions[A] + pos*Dimensions[D]];


But what I get for any integer value of pos is always:

I would like to be able to fill the Matrix in this way, so that if I leave holes in between they show up in the end.

I would like to have, for:

Dmat = IdentityMatrix[5]


And pos=7, the following output

Does somebody understand the logic here and can help me with this?

Thanks!

• You have described twice what you don't want, but you have not described what matrix structure you do want. Nov 19, 2014 at 4:21
• Thanks @bills I uploaded now the desired input and desired output and removed my useless function. Nov 21, 2014 at 2:09

Perhaps this is a way:

am = IdentityMatrix[3];
cm = {{c, c, c, c, c}, {d, d, d, d, d}, {e, e, e, e, e}};
dm = IdentityMatrix[5]

ArrayFlatten[
Normal[SparseArray[{{1, 1} -> w[am], {1, 6} -> w[cm], {6, 1} ->
w[Transpose@cm], {6, 6} -> w[dm]}, {6, 6}]] /.
w -> Sequence] // MatrixForm


where w is just a wrapper to allow SparseArray` to parse.

• Sorry, I forgot to accept this. It works really well, This little trick of the wrapper w is pretty nice! Nov 24, 2014 at 15:07