How to subtract entire column of matrix
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!