MATLAB: How to determinine if a sequence is consecutively increasing

continuous serieslower bound

Dear Community:
I have a data curve that exponentially increases. I wish to find over what times a certain continuous range of data lies. The problem lies in that at the upper bound, there will be some points that lie above the upper bound and then come back down, yielding a non-consecutive index series using the MATLAB find function. I wish to then find only the consecutively increasing values of the index and then find the first instance where the upper bound value is reached.
As an example: say I have the exponential series S = [1 4 9 16 25 36 …]. Finding the index over the range where the values fall (inclusively) between 4 and 25 is then [2 3 4 5] (using find(S >= 4 & S <= 25]. This then gives a time range of 4 units long where the increase occurs.
BUT real data is noisy and the real data is more like R = [ 1 4 9 16 27 24 25 36 …]. If I naively use the find function to find the range over where R <= 25 and R >= 4, I would get [2 3 4 6 7] and conclude the range is 5 units long–which is wrong. The upper value is reach at 27, so the range is actually 4 units long.
Clearly finding the first occurrence where the criteria occurs is needed, but I am wondering if there there a function or more straight forward way to find a consecutively increasing range in MATLAB?
I hope I've explained this problem adequately and thank you for your feedback!

Best Answer

You apparently don’t want to use the diff function, but in this instance it may be what you need.
See if this does what you want:
R = [ 1 4 9 16 27 24 25 36];
Rix = find((diff([0 R]) > 0) & (R >= 4) & (R <= 25))