필터 지우기
필터 지우기

Area under curve of data points (no function) with x and y boundary

조회 수: 4 (최근 30일)
Noa Hoogeweg
Noa Hoogeweg 2020년 10월 18일
댓글: Ameer Hamza 2020년 10월 20일
Hello, how can I compute the area under a curve (see green area) of data points with a x and a y boundary? The x boundary = 70 and y=0.05. I tried trapz but I don't know how to use this with an x and an y boundary. The curve is made up of data points imported from excel:
x= xlsread(datafile, 'x-axis', 'B5:MI5');
y=xmid = xlsread(datafile, 'y-axis', 'B5:MI5');
area = trapz(x,y) %this gives the whole area under the red curve, but I only want the green area
I hope someone can help me, thanks!

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 18일
편집: Ameer Hamza 2020년 10월 18일
Something like this
mask = x > 70;
xv = x(mask);
yv = y(mask);
trapz(xv, yv-0.05); % if all the points are above x-axis then just subtracting 0.05 is enough.
  댓글 수: 4
Noa Hoogeweg
Noa Hoogeweg 2020년 10월 20일
I modified it a bit, and I think this works better in general:
mask = x >= 70;
xv = x(mask);
yv = y(mask);
trapz(xv(yv>=0.05), yv(yv>=0.05));
Correct me if I'm wrong :)
Ameer Hamza
Ameer Hamza 2020년 10월 20일
Yes, If you only want to integrate when y is above 0.05 then it is correct.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by