Calculate the area between two curves
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (1)
the cyclist
le 9 Fév 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 commentaire
Rhynchophorus
le 10 Fév 2021
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!