2

I have three matrices I would like to Join at level 3:

table1= Table[0, {5}, {30}, {4}];
table2= Table[0,{5],{30}];
table3= Table[0,{5],{30}];

My first question would be how to Join the above lists in a way so I get

table4= Table[0, {5}, {30}, {6}];

I have tried this to no avail with the Join command, receiving the error message: "at position 2 is expected to have head List for all expressions at \ level 3", which I take to mean, it cant Join because one table doesn't have a level 3.

My second question would be generally whether I can combine the Join-command for multiple lists but also at a specific level. As in Join[table1,table2,table3,3], which of course does not work.

I am very grateful for any and all help.

Thank you very much, Benjamin

Ben.F
  • 43
  • 4

1 Answers1

0

Join a list with {6, 6, 2} dimensions with a list {6, 6} dimensions

The linked topic is very closely related but answers there except two matrices not more, here are few generalizations:

MapThread[Join[#, {##2}] &, {table1, table2, table3}, 2]

Flatten /@ Thread[{#1, ##2}] & @@@ Transpose[{table1, table2, table3}]
Kuba
  • 136,707
  • 13
  • 279
  • 740