Calculate the area between two curves
Show older comments
I'm trying to calculate the area between two curves with different x-coordinate values.
I have tried using the trapz function found on other posts but recieve this error: "Point spacing must be a scalar specifying uniform spacing or a vector of x-coordinates for each data point" because of the different x-coordinate.
Is there an easy work around to this or a function that can handle non-uniform x-coordinates?
Data is attached.
Thanks.
Accepted Answer
More Answers (1)
the cyclist
on 9 Feb 2021
Because your curves are smooth, I think using interpolated curves will be useful:
xx = 0 : 0.01 : min(max(x1),max(x2));
yy1 = interp1(x1,y1,xx);
yy2 = interp1(x2,y2,xx);
Use the yy1 and yy2 variables, along with the uniformly spaced xx variable (same for both curves) to calculate areas.
1 Comment
Rhynchophorus
on 10 Feb 2021
Categories
Find more on Numerical Integration and Differentiation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!