How to subtract entire column of matrix

1 visualización (últimos 30 días)
Tim B
Tim B el 5 de Jun. de 2017
Comentada: Tim B el 5 de Jun. de 2017
Suppose I have a 5x2 matrix such as
a = [1.20;.976;.833;.702;.543];
b = [1663;1058;953;802;744];
z = [a,b];
I want subtract each column such that 1.20 - .976 - .833 - .702 - .543 and 1663 - 1058 - 953 - 802 - 755
The main goal is to get a 1x2 matrix with the difference of these columns which in this case would be
[-1.854,-1905]
I tried using the diff and sum command but they would just add everything up which isn't the same as subtracting each value. I know I can easily use a calculator to find this answer but if I had a 20x2 matrix it wouldn't be as practical.
What would be the simplest way to calculate this?

Respuesta aceptada

the cyclist
the cyclist el 5 de Jun. de 2017
[2*a(1)-sum(a) 2*b(1)-sum(b)]

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by