MATLAB: How to subtract elements in array? (1 x 40)

arrayscell arraysMATLABmatrix

For example:
A = [8 3 10 7 15 12 16 14 20 18 12 8]
so that I can create two variables that are the difference between each pair in the vector..
result1 = [5 3 2] --> "[(8-3) (15-12) (20-18]"
result2 = [3 2 4] --> "[(10-7) (16-14) (12-8)]"

Best Answer

all_results = -diff(reshape(A,2,[]));
result1 = all_results(1:2:end);
result2 = all_results(2:2:end);