Finding the x value where there area under the curve (from the centre) is 80% of total area

1 次查看(过去 30 天)
Hi. I have a set of data points that I perform a spline to to fill in the gaps. I have split the spline into two splines - one each side of the max (black dotted line).
I want to find the area for each half, starting with the blue spline and at the peak x value (i.e.black dotted line) and find the x coordinate that equates to 80% of the total area under the curve. I have tried to use cumsum, but am not getting sensible answer.
cdf = cumsum(horizontalProfile1(1:indexOfMax));
sum(cdf)
% Normalize
cdf = cdf / sum(cdf)
width80 = 2 * find(cdf >= 0.8, 1, 'first')
title(['E80 ',num2str(width80)],'fontsize',10,'FontWeight','normal','Color','b')
It might be because Im summing from 1 to index of max, but even when I switch it it gives an empty matrix for width50?

采纳的回答

Guillaume
Guillaume 2016-11-21
编辑:Guillaume 2016-11-21
Your normalisation is completely wrong. You need to divide by the total area which is sum(horizontalProfile1(1:indexOfMax)), or cdf(end), not the sum of the cumsum.
cdf = cdf / cdf(end); %or cdf = cdf / sum(horizontalProfile1(1:indexOfMax)) %same number
You were dividing the cumsum by such a huge number that the normalised cdf never went above 0.8, thus find returned empty.

更多回答(1 个)

KSSV
KSSV 2016-11-21
doc trapz.

类别

Help CenterFile Exchange 中查找有关 Spline Postprocessing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by