Filter löschen
Filter löschen

Calculate the Area Between Two Curves

1 Ansicht (letzte 30 Tage)
Allison Bushman
Allison Bushman am 5 Mär. 2019
Beantwortet: Rik am 5 Mär. 2019
I am trying to calculate the area between these two curves:
cP6(k,:)=P6;
cP7(k,:)=P7;
plot(cP6(:,1),cP6(:,2),'LineWidth',2,'Color','red');
plot(cP7(:,1),cP7(:,2),'LineWidth',2,'Color','blue');

Antworten (1)

Rik
Rik am 5 Mär. 2019
This code should help. It assumes you want to count all the area between the two lines as positive. The more crossings there are, the more this code will give an overestimation.
cP6(k,:)=P6;
cP7(k,:)=P7;
x1=cP6(:,1);
y1=cP6(:,2);
%x2=cP7(:,1);
y2=cP7(:,2);
%if x1 and x2 are not the same, you will need to resample them,
%or use polyarea instead of trapz
A=trapz(x1,abs(y1-y2));

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by