MATLAB: Inverse/opposite of diff function

additiondiff functioninverse diffopposite diffprevious element

I have a 480×640 matrix and would like to perform the diff function on the elements but instead of subtracting the previous element I would like to add it.
I have tried using x(2:end) + x(1:end-1) Which return the right values but instead of returning a 479×640 matrix it returns a 1×307199 matrix. How can I change the function to give the 479×640 matrix.
Thanks in advance

Best Answer

x(1:end-1,:) + x(2:end,:)
Best wishes
Torsten.