MATLAB: How to add or subtract any given matrix value with its following value

matrix manipulation

Say I have a matrix [1:1:10], and I would like to add(or subtract) the first value with the second value. And I want Matlab to repeat this for all values within the matrix. i.e. 1+2, 2+3, 3+4 and so on, until 9+10. I imagine that the code has to use i and i+1, where i is any given value within my matrix. But how do I write this down in my script? Any ideas are appreciated.

Best Answer

>> vec = [1,2,3,6,8,0];
>> vec(1:end-1)+vec(2:end)
ans =
3 5 9 14 8
or using your example:
>> vec = 1:10;
>> vec(1:end-1)+vec(2:end)
ans =
3 5 7 9 11 13 15 17 19