Query regarding finding the index which will give 90% of the total area under the curve
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
NAVNEET NAYAN
am 26 Nov. 2020
Kommentiert: John D'Errico
am 28 Nov. 2020
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.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 26 Nov. 2020
Bearbeitet: Walter Roberson
am 26 Nov. 2020
A = cumtrapz(x, y);
x_idx = find(A >= 0.9 * A(end), 1);
0 Kommentare
Weitere Antworten (1)
John D'Errico
am 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
cumtrapz(x,y)/trapz(x,y)
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.
2 Kommentare
John D'Errico
am 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.
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!