Subtraction of rows in matrices

1 view (last 30 days)
Serena Solanki
Serena Solanki on 21 Nov 2017
Answered: Star Strider on 21 Nov 2017
Hi All, Hope you can help
I have a 2x5000 matrix and I want to subtract the first row from the second row.
I have tried vectorising them but it isn't working
For example dn=[1 2 4 5 6 7 7
3 5 6 7 8 9 9]
i want to subtract the first row from the second.
Any ideas how i can do this without vecotirsing each row?
Thanks

Answers (2)

Stephen23
Stephen23 on 21 Nov 2017
>> diff(dn)
ans =
2 3 2 2 2 2 2

Star Strider
Star Strider on 21 Nov 2017
I do not know what you mean by ‘vectorize’.
Regardless, use the diff funciton:
dn=[1 2 4 5 6 7 7
3 5 6 7 8 9 9]
Result = diff(dn)
Result =
2 3 2 2 2 2 2

Categories

Find more on Programming 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!