8
$\begingroup$
a = {{-800, 1712}, {-801, 1713}, {-806, 1832}}
TableForm[a]
b = a[[All, 2]] - Min[a[[All, 2]]]

How do I make a new matrix (list) whic looks like this

-800  1712 0
-801  1713 1
-806  1832 120

The 3rd column, takes the difference between the value from the 2nd column and it's minimum of the whole 2nd column.

I tried to Join the two, but with no success.

Thanks.

$\endgroup$
0

1 Answer 1

13
$\begingroup$

Perhaps I've missed something, but you seem to just want to append a vector (which you have already calculated) to a matrix.

Documentation for Append[] shows how to do it:

enter image description here

For your case since you already have a and b:

MapThread[Append, {a, b}] // MatrixForm

enter image description here

A different approach enables you to join matrixes to make longer rows:

The following makes a 2 column matrix from your b

b2 = Transpose[{b, b}];
b2 // MatrixForm

enter image description here

The documentation for Join[] shows the way to do what you asked for in your comment:

enter image description here

Note that the 2 at the end of the Join[] operates as a level specification.

For your case:

Join[a, b2, 2];
% // MatrixForm

enter image description here

$\endgroup$
2
  • $\begingroup$ How would I Append two columns? Do I have to use MapThread[Append, { MapThread[Append, {a, b}], b} ] // TableForm, or there is an easy way? Thanks. $\endgroup$ Commented Dec 6, 2014 at 16:34
  • $\begingroup$ @ChenStatsYu - see addition to the answer. $\endgroup$
    – Jagra
    Commented Dec 6, 2014 at 19:01

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