How to subtract entire column of matrix

1 回表示 (過去 30 日間)
Tim B
Tim B 2017 年 6 月 5 日
コメント済み: Tim B 2017 年 6 月 5 日
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?

採用された回答

the cyclist
the cyclist 2017 年 6 月 5 日
[2*a(1)-sum(a) 2*b(1)-sum(b)]
  1 件のコメント
Tim B
Tim B 2017 年 6 月 5 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by