Query regarding finding the index which will give 90% of the total area under the curve
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
NAVNEET NAYAN
el 26 de Nov. de 2020
Comentada: John D'Errico
el 28 de Nov. de 2020
I have a curve obtained using curve fitting toolbox.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/429423/image.jpeg)
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 comentarios
Respuesta aceptada
Walter Roberson
el 26 de Nov. de 2020
Editada: Walter Roberson
el 26 de Nov. de 2020
A = cumtrapz(x, y);
x_idx = find(A >= 0.9 * A(end), 1);
0 comentarios
Más respuestas (1)
John D'Errico
el 26 de Nov. de 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 comentarios
NAVNEET NAYAN
el 26 de Nov. de 2020
Editada: NAVNEET NAYAN
el 26 de Nov. de 2020
John D'Errico
el 28 de Nov. de 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.
Ver también
Categorías
Más información sobre Least Squares en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!