3

Suppose I have following table-

 1   5   8
 2   6   9
 3   7   10
 0   0   0

Now, I want to add another column by exporting a data file. Suppose contents of that data file are-

 11
 12
 13
 54

I want to merge these two tables to look something like-

 1   5   8    11
 2   6   9    12
 3   7   10   13

I want to delete that row where elements of first table are all zero. I tried Join command but It is not working.

solphy101
  • 337
  • 2
  • 12
  • Transpose the table, Append the new row, Transpose back, and Drop the last row ? – LouisB Apr 28 '17 at 05:20
  • I think this question was asked and answered many times before. I'm linking topics where you can find those answers. Let me know if you disagree. Also related: 20228, 108336 – Kuba Apr 28 '17 at 06:30
  • m1 = {{1, 5, 8}, {2, 6, 9}, {3, 7, 10}, {0, 0, 0}}; m2 = {11, 12, 13, 54}; Most@MapThread[Append, {m1, m2}] – webcpu Apr 28 '17 at 06:53

2 Answers2

2

one way might be

 (mat = {{1, 5, 8}, {2, 6, 9}, {3, 7, 10}, {0, 0, 0}}) // MatrixForm

Mathematica graphics

 mat = Insert[Transpose[mat], {11, 12, 13, 54}, -1];
 (mat = Transpose[mat]) // MatrixForm

Mathematica graphics

  (mat=DeleteCases[mat, {0, 0, 0, _}]) // MatrixForm

Mathematica graphics

Nasser
  • 143,286
  • 11
  • 154
  • 359
1
a = Table[i + j*i, {i, 1, 4}, {j, 1, 3}];

2   3   4
4   6   8
6   9   12
8   12  16


b = Transpose@Join[Transpose@a, {{1, 1, 1, 1}}]

2   3   4   1
4   6   8   1
6   9   12  1
8   12  16  1
Rom38
  • 5,129
  • 13
  • 28