How to plot and calculate these area under the curve
5 views (last 30 days)
Show older comments
Hello,
I've a set of data x and y, that give me a figure below
x = [0.02 0.07 0.18 0.37 0.56 0.68 0.73 0.76 0.80 0.83 0.88 0.94 1.00 1.06 1.13 1.17 1.20 1.24 1.27 1.32 1.44 1.64 1.88 2.20];
y = [1.011 1.011 1.011 1.006 0.976 0.931 0.907 0.890 0.874 0.859 0.839 0.817 0.809 0.816 0.836 0.855 0.870 0.887 0.904 0.930 0.975 1.003 1.006 1.005];

I would like to calculate the area in red, grey and yellow. The code that I am using cannot distinguish between the areas above and below (i-e y = 1) and miscalculating it
----------------------------------------------------------------------------------------
level = 1;
lineStart = find(y<=level,1);
lineEnd = find(y(lineStart:end)>=level,1)+lineStart;
plot(x,y)
hold all
area(x(lineStart:lineEnd),y(lineStart:lineEnd),level)
line([x(lineStart),x(lineEnd)],[level level])
hold off
grid
A = trapz(x(lineStart:lineEnd),y(lineStart:lineEnd))
-------------------------------------------------------------------------------------------
Any help or suggestion is appreciated !!
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!