How to determinine if a sequence is consecutively increasing?

6 views (last 30 days)
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!
  1 Comment
Kevin Johnson
Kevin Johnson on 23 Aug 2015
Just was thinking of a possible workaround (not elegant though):
Using the diff function for a series S, find(diff(S) > 1) will give the index where the consecutive differences of values are non-unity. Then you can take the first value of this index to then get the first occurrence of the upper bound criteria for the range you want.
But surely there is a nicer way to this! Elegance and compactness of code is far more efficient.
Thanks for any feedback or comments on this suggested approach here above.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 23 Aug 2015
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))

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!