Query regarding finding the index which will give 90% of the total area under the curve
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2020-11-26
编辑:Walter Roberson
2020-11-26
A = cumtrapz(x, y);
x_idx = find(A >= 0.9 * A(end), 1);
0 个评论
更多回答(1 个)
John D'Errico
2020-11-26
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 个评论
John D'Errico
2020-11-28
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!