Home > database >  Matlab trapz but splitting areas above and below the x-axis
Matlab trapz but splitting areas above and below the x-axis

Time:12-15

I'm trying to find the area under a curve in the region both above the x-axis (from y = 0 to inf) and below the x-axis, (y = 0 to -inf), separately.

As far as I can figure out, I can use

int = trapz(x,y)

to get the area under the curve, but not as 2 separate values.

For example, if we have x = [0,1,1,2] & y = [7,7,-4,-4]

Trapz will work out "3" as the area ((7.*1) (-4.*1)), but I want the values of the area above the x-axis and below the x-axis as 2 separate numbers, 7 & -4.

Trapz must fit the trapezoids, calculate the area of the trapezoids and then sum over all. I want a way to fit & find the areas of the trapezoids, but then sort them in to ve & -ve and finds the sum's of the ve and -ve areas.

The documentation for trapz: plot

As a sense check, using the above gives the same output for aTotal as trapz(x,y).

  • Related