I want to do padding of matrix
a = {{x,x},{x,u}};
to
b = {{x, x, x}, {x, u, u}, {x, x, x}}
c = {{x, x, x, x}, {x, u, u, u}, {x, x, x, x}, {x, x, x, x}}
and soon...
How I can automatically do this?
I want to do padding of matrix
a = {{x,x},{x,u}};
to
b = {{x, x, x}, {x, u, u}, {x, x, x}}
c = {{x, x, x, x}, {x, u, u, u}, {x, x, x, x}, {x, x, x, x}}
and soon...
How I can automatically do this?
You might use:
a = {{x, x}, {x, u}};
{#, #2, #} & @@ ArrayPad[a, {0, {0, 3}}, "Fixed"]
{{x, x, x, x, x}, {x, u, u, u, u}, {x, x, x, x, x}}
ArrayPad. I am still uncertain about ultimate aim.
– ubpdqn
Mar 17 '14 at 03:58
I must confess to being confused about the ultimate aim. I, therefore, am sorry if these speculations miss the mark.
If the aim is to progressively pad right with the last element of every list then:
g[s_, n_] := PadRight[#, n, Last@#] & /@ s
Repeatedly applying:
Column[Table[g[a, j], {j, 3, 6}]]
yields:

If the intent is to sequential pad right with the first element then pad right with the last element of each subset then:
f[s_] := With[{w = First[s]},
ReleaseHold[PadRight[s, Length[s] + 1, Hold[w]]]];
You can get lists:
FoldList[g[f[#1], #2] &, a, Range[3, 6]]

If the aim is just to expand first list then apply g:
Table[g[f[a], j], {j, 3, 6}]

The latter seems to be consistent with outcome presented. However, I may have misunderstood intent.
base = {{x, x}, {x, u}, {x, x}}
pads = Rest@NestList[Function[arg, PadRight[#, Length@# + 1, Last@#] & /@ arg],base, 4];
Each entry of pads is one more level of padding.
Change the 4 in the NestList to however many different levels of padding you want produced.
Perhaps a bit "cleaner", same results:
Rest@NestList[ArrayPad[#, {{0, 0}, {0, 1}}, "Fixed"] &, base, 4]
ArrayFlatten. – Szabolcs Mar 16 '14 at 22:39