I have a velocity dataset [stored in 700 x 1 double] that i want to get the total displacement of (eg: I don't want net displacement. For total displacement, any negative displacement I would flip it to positive values). Normally, I would use cumtrapz again to gain the displacement, however any positive or negative displacements would cancel each other out. I don't want that.

I know that the area under the velocity curve is supposed to yield the total displacement. What would be the best way to code it such that the negative area is captured as positive area? Please note that I do not have points that are exactly zero (so point 1 may be +0.7 and point 2 may be -0.5, but it does not have a point in the discrete data which shows 0). I cannot simply just make the y outputs as all absolute value, because integrating between +0.7 and +0.5 yields a different area than +0.7 and -0.5. Any help would be greatly appreciated.