Find the area under a certain section of a plot

3 views (last 30 days)
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.

Answers (1)

Samatha Aleti
Samatha Aleti on 31 Jan 2020
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);

Categories

Find more on Two y-axis in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!