Clear Filters
Clear Filters

Finding the exact end of decay period

3 views (last 30 days)
Hello All, I have some data such as the file attached. I want to know how I can find the exact end of the decay period so that I can later fit a linear line to my data. In my example, I want to know how to find the 10th data point automatically so that I can fit a linear line to data points from 1 to 10 not the whole data points. Basically I want MATLAB to find the exact end of the decay period. Because after the 10th point there is essentially no decay. Thanks everyone in advance.

Accepted Answer

Star Strider
Star Strider on 28 May 2017
One option is to use the diff function on the y values, then define the end as the first occurrence of a positive value. The problem with diff is that the output is one element shorter than the input.
You can do a similar approach with the gradient function. The advantage of using gradient is that the length of the output vector is the same as the input vector, making addressing easier. So, the first positive value of the derivative is the end of the data you want to use.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!