Query regarding finding the index which will give 90% of the total area under the curve

5 views (last 30 days)
I have a curve obtained using curve fitting toolbox.
I calculated the area of this curve using both 'trapz' and 'polyarea' function. I got this around 35704 square units. Now, I want to find the index on the X-axis till which my area is 90% of total area (i.e. 90% of 35704 square units). Is there any function for this?
If the question is not clear, feel free to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Nov 2020
Edited: Walter Roberson on 26 Nov 2020
A = cumtrapz(x, y);
x_idx = find(A >= 0.9 * A(end), 1);

More Answers (1)

John D'Errico
John D'Errico on 26 Nov 2020
No. You found some approximations of the area, using either trapz or polyarea. In both cases, they produced what is a trapezoidal rule approximation to the area, since they are implicitly piecewise linear tools. You do not give us any clue how that curve was "obtained" from the curve fitting toolbox, but since that toolbox does not provide data in any way, we are at a loss to know what you mean by that comment.
If you used trapz however, you can trivially use cumtrapz. I lack your data, so I cannot use it as an example. But, trivially if you find the location where
is approximately 0.9, then you have found the 90% point on your curve. You can use interp1 to do that interpolation, either to find an interpolated point, or to find the index which is closest to 0.9 in area. You could also just use discretize to find the location, from the cumulative integral curve. Take your pick of the methods I have described. Depending on the curve itself, if you actually fit the curve with some model from the curve fitting toolbox, there are many other things you could hve done. But for that, you would need to be forthcoming with real information.
John D'Errico
John D'Errico on 28 Nov 2020
You need to be careful if you are using a cubic interpolant of any form to plot a noisy function. Note the solution for the are that I showed (the same as what was shown by Walter) uses an implicitly PIECEWISE LINEAR interpolant. But then you plot the curve using a cubic interpolant. You want to be consistent.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!