Or ...
Using ConstantArray:
mat0 := Most@Flatten[#, 1] & /@
({#, .25 + #} & /@ ConstantArray[#, Ceiling[(Length@#)/2]]&@
Range[0, #, .5] &) ;
mat0@2.2
(* gives *)
{{0., 0.5, 1., 1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1.,
1.5, 2.}, {0.25, 0.75, 1.25, 1.75, 2.25}, {0., 0.5, 1., 1.5,
2.}}
Using Table:
mat2:=Most@Flatten[#, 1] & /@ (Transpose /@
Table[{#, .25 + #} & /@ #, {Ceiling[(Length@#1)/2]}] &@ Range[0, #, .5] &)
Using NestList:
mat3:=Most@Flatten[#, 1] & /@
(NestList[Join, {#1, #2}, Floor[(Length@#1)/2]] & @@ {#, .25 + #} &
@Range[0, #, .5] &)
Using Table again (less cluttered and more general):
mat4:= Table[{#2, #1}[[1 + Mod[i, 2]]], {i, #3}] &;
mat5 := Table[{#1, #2}[[1 + Mod[i, 2]]], {i, 0, #3 - 1}] &;
mat4[{a, b, c, d}, {e, f, g}, 5]
(* and *)
mat5[{a, b, c, d}, {e, f, g}, 5]
(* both give *)
{{a, b, c, d}, {e, f, g}, {a, b, c, d}, {e, f, g}, {a, b, c, d}}
x == 2.5? Or, disregarding thexissue, what if the dimension ofais even (I suppose the matrix must be square in all cases) – Leonid Shifrin Feb 11 '12 at 22:28xisn't an integer. – Heike Feb 11 '12 at 22:33xis fragile. I'd useLength[a]in place ofFloor[2x+1]. – Leonid Shifrin Feb 11 '12 at 22:38f[x_Integer]:) – CHM Feb 11 '12 at 22:44Moduleobscured it. – Mr.Wizard Feb 11 '12 at 23:15