Find the area under a certain section of a plot

6 次查看(过去 30 天)
I have a set of data that I have used to plot the graph below. I am needing to find the area of the shaded area but cannot work out how to as I do not know what range of values make up this section and, as the data loops round multiple times there will be a few sets. The data used was two 2000x1 double vectors. Any help would be appreciated.
untitled.jpg
Note: The shading was done in photoshop as I do not know how to do this in Matlab earlier.

回答(1 个)

Samatha Aleti
Samatha Aleti 2020-1-31
You can do this by finding the points of intersection of the curve(y1) and the line(y2). Let the intersection points be “[x1,y1] and[x2,y2]. You can find the area using "integral" function.Here is a sample code:
x1 = 1; % Let
x2 = 5; % Let
xmin = min(x1,x2);
xmax = max(x1,x2);
y1 = @(x) (x.^2)+2; % Curve
y2 = @(x) 2*x; % Line
fun = @(x) ((x.^2)+2 - 2*x); % y1-y2
area = integral(fun,xmin,xmax);

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by