4

I have a row vector like so: [1 5 6 -4 3]. I want to find means of absolute values of second difference between elements. The second differences in this example are (6-1)=5 ,-4-5=-9 & 3-6=-3, and the average absolute mean is (5+9+3)/3=17/3.

Is there some way of using MATLAB's efficient matrix/array manipulation to do this nicely?

Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104
Tony YEe
  • 235
  • 1
  • 3
  • 13
  • I was wondering if there is a way to use `diff` to compute the second difference, but the results I get are different (`diff(v,2) = [-3, -11, 17]`). – Yamaneko Oct 23 '12 at 03:46
  • @VictorHugo: The N-th order difference (`diff(x,N)`) means calling `diff` recursively `N` times. So `diff(X,2)` equals `diff(diff(X))`. For *this* operation however, use @Cyrgo's answer. – Rody Oldenhuis Oct 23 '12 at 04:04

1 Answers1

3

For the second difference you can do the following (v is your vector):

v(3:end)-v(1:end-2)

and from there to calculating the mean of the abs olute value, its really a simple step.

R. Schifini
  • 9,085
  • 2
  • 26
  • 32