MATLAB Answers

0

Subtraction of rows in matrices

Asked by Serena Solanki on 21 Nov 2017
Latest activity Answered by 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

  0 Comments

Sign in to comment.

2 Answers

Answer by Stephen Cobeldick on 21 Nov 2017

>> diff(dn)
ans =
2 3 2 2 2 2 2

  1 Comment

Ah thank you !

Sign in to comment.


Answer by 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

  0 Comments

Sign in to comment.