2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Transpose the table, Append the new row, Transpose back, and Drop the last row ? $\endgroup$ – LouisB Apr 28 '17 at 5:20
  • $\begingroup$ 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 $\endgroup$ – Kuba Apr 28 '17 at 6:30
  • $\begingroup$ m1 = {{1, 5, 8}, {2, 6, 9}, {3, 7, 10}, {0, 0, 0}}; m2 = {11, 12, 13, 54}; Most@MapThread[Append, {m1, m2}] $\endgroup$ – UnchartedWorks Apr 28 '17 at 6:53
2
$\begingroup$

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

| improve this answer | |
$\endgroup$
1
$\begingroup$
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
| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.