MATLAB Answers

How to calculate partial area-under-the-curve?

133 views (last 30 days)
M G
M G on 22 Mar 2014
Commented: Laura Kim on 27 May 2019
Hi all,
I am trying to find the area under the curve (AUC) for a part of a graph. I use "trapz" function, but this function calculates the AUC for a entire area below the selected part of the graph. Any hint how I can calculate only part of it (not entire part until x-axis)? Please see figure. Interested are to be calculate is in red.
Thanks, Mehdi
(for simulation of data, just generate a random vector and try a part of it.)

  0 Comments

Sign in to comment.

Accepted Answer

Mischa Kim
Mischa Kim on 22 Mar 2014
Mehdi, use trapz twice to subtract the area below the red marked one (between x-axis and data points y = 0.3111, 0.1848 ) from the entire area.

  3 Comments

M G
M G on 22 Mar 2014
That makes a good sense. We can calculate the area of the irregular trapezoid just below the red part and subtract it from whole area. But how can I ask matlab to calculate that area under the red part? Because the code:
trapz(data(221:224))
takes the entire part! unless we first generate second graph in that part where we draw a line between data(221) and data(224) to make a trapeziod and then calculate the trapz of this secondary part. Or any better idea? Thank you :)
Mischa Kim
Mischa Kim on 22 Mar 2014
This should do
trapz(data(221:224)) - trapz([221 224],[data(221) data(224)])
Laura Kim
Laura Kim on 27 May 2019
Hi I was wondering if this method worked.
thank you

Sign in to comment.

More Answers (0)