Calculate the area between two curves
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (1)
the cyclist
am 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 Kommentar
Rhynchophorus
am 10 Feb. 2021
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!