Calculate the Area Between Two Curves

1 view (last 30 days)
Allison Bushman
Allison Bushman on 5 Mar 2019
Answered: Rik on 5 Mar 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');

Answers (1)

Rik
Rik on 5 Mar 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!