MATLAB: Filtering by the second derivative

diff()logical?MATLAB

I have an array, and I'm trying to figure out how to mark the values where the second derivative is above a threshold. To get the second derivative I'm doing
diff(diff(array)), the problem is that creates a result of length(array)-2, and I want to created a logical array for the original array.
For example, with
arr = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34];
and a filter of x < 2, I'd like to produce:
[1,1,1,1,1,1,1,0,0,0]
since the second derivative is
[-1,1,0,1,1,2,3,5]
Hopefully that makes sense.

Best Answer

gradient(gradient(arr)) < 2
Watch out for < 2 compared to <= 2