Find the area under a certain section of a plot

6 ビュー (過去 30 日間)
Andrew Powell
Andrew Powell 2020 年 1 月 8 日
回答済み: Samatha Aleti 2020 年 1 月 31 日
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);

カテゴリ

Help Center および File ExchangeSmoothing についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by