How can I calculate the area between two curves in a specific section?

조회 수: 4 (최근 30일)
daniel ordnung
daniel ordnung 2020년 1월 27일
댓글: daniel ordnung 2020년 2월 2일
I have two curves which have several intersection points (see attachment). I want to calculate the green filled area in between two intersection points. It works to calculate and display the intersection points. However I am struggling to calculate just this specific (green filled) area with the trapz function since there always pops up following error message:
"Index in position 1 is invalid. Array indices must be positive integers or logical values."
[xj,yj] = polyxpoly(x,y1,x,y2); %calculate intersection points %y1 straight line %y2 mean
mapshow(xj,yj,'DisplayType','point','Marker','o');%show intersection points
A=[xj,yj];
for n=length(xj):-1:1
k=A(n,:);
k(:,2)=[];
l=A(n-1,:);
l(:,2)=[];
isec1= find(y2==l);
isec2= find(y2==k);
a = trapz(isec1:isec2,y1(isec1:isec2,1))-trapz(isec1:isec2 ,y2(isec1:isec2,1));
end

답변 (1개)

Priyanshu Mishra
Priyanshu Mishra 2020년 1월 31일
Hi Daniel,
When n=1, n-1 goes to zero for which A(0,:) is an invalid index. The error you are getting is becuse of this only.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by