hello I hope you can help me!
as per diagram below, I have a curve (blue) and a straight line (pink) say y=1.
I will need to find the unit area under the curve (yellow area) and "over" the curve (green area).
also the curve dont have many data points, I hope this wouldn't be a huge problem!
Please advise and many thanks in advance!
xLast = find(y > 1, 1, 'last'); areaUnderCurve = sum(abs(y(1:xLast) - 1))
This is basically assuming the digitized y is a bar chart and you're summing the heights of the rectangular bars. Of use trapz() if you want trapezoids instead of rectangular bars.
ok I figured it out, thanks for you help!
x=[0,5,10,20,50,100,150,250,350,450]; b=[4.01E-01,8.30E-01,9.49E-01,1.08E+00,1.21E+00,1.23E+00 ,1.20E+00,1.12E+00,1.11E+00,9.69E-01]; line=[1,1,1,1,1,1,1,1,1,1];
x_fine=0:10:450 b_fine = interp1(x,b,x_fine,'spline'); figure plot(x,b,'o',x_fine,b_fine,'r', x,line,'b');
xFirst = find(b_fine > 1, 1, 'first'); xLast = find(b_fine > 1, 1, 'last');
area_total = trapz(x_fine,b_fine-1) area_Loss = trapz(x_fine(1:xFirst),b_fine(1:xFirst)-1) area_Gain = trapz(x_fine(xFirst:xLast),b_fine(xFirst:xLast)-1)