MATLAB: How to find the point which exceeds the previous 50 data points in a graph

findgraphthreshold

I am looking for a way to find the point which exceeds the previous 50 datapoints. My proposal to an equation which does this is: "x = find(f > f(x-50:x), 1, ’first’);" but I get the an error since x is not defined in the workspace.

Best Answer

Use movmax to calculate the moving maximum of your datapoints with a window of [50 0]. You then use a simple comparison to find which points are above this moving maximum:
find(f(2:end) > movmax(f(1:end-1), [50 0])) + 1
Unfortunately, as movmax always include the current element, you have to do a bit of index shifting, hence the 2:end and 1:end-1. (You can't specify a window of [50 -1])
Related Question