MATLAB: How to obtain the absolute difference between elements in a row

absolute differencematrixrow

Hi I have
a= 4 3 2 1
4 3 1 2
4 2 3 1
I want to know the absolute difference between elements for each of the rows which gives me
b= 1 1 1
1 2 1
2 1 2
How am I going to do this? Thank you.

Best Answer

b = abs(diff(a, 1, 2))