How to calculate partial area-under-the-curve?

392 ビュー (過去 30 日間)
Jacqueline Rigatto 2021 年 3 月 15 日

Hi, I'm trying to find the area under the curve (ABC) for a part of a graph. I use the "trapz" function, but this function calculates the ABC for an entire area below the selected part of the graph. Any tips on how I can calculate only part of it (not the whole part up to the x axis)? Please see the figure. Interested are to be calculate is in red.
Thanks, Jacqueline

サインインしてコメントする。

採用された回答

Star Strider 2021 年 3 月 15 日
Use trapz twice, once to integrate (A, B, C), and again to integrate (A, C).
Then subtract the (A, C) result from the (A, B, C) result.
It would definitely help to have the data, preferably as a .mat file.
27 件のコメント表示非表示 26 件の古いコメント
Jacqueline Rigatto 2021 年 4 月 12 日
Thanks for all the help, Star Strider

サインインしてコメントする。

その他の回答 (2 件)

John D'Errico 2021 年 4 月 4 日
After all of those comments, to be honest, sorry, but you were both working far too hard on a moderately simple problem.
Simplest is to just create a polygon, then use polyarea of that object. Alternatively, create a polyshape object. Again, compute the area of said polygonal region.
help polyshape
help polyshape/area
AREA Find the area of a polyshape A = AREA(pshape) returns the area of a polyshape. The area is the sum of the area of each solid region of pshape. A = AREA(pshape, I) returns the area of the I-th boundary of pshape. This syntax is only supported when pshape is a scalar polyshape object. See also perimeter, centroid, sortboundaries, polyshape Documentation for polyshape/area doc polyshape/area
The result will be a piecewise linear approximation to the area. That is the same result you will get from trapz anyway, since trapz is simply a tool that performs integration using linear segments to connect the points.
1 件のコメント表示非表示 なし
Jacqueline Rigatto 2021 年 4 月 12 日
Thank you for the help, John D'Errico

サインインしてコメントする。

Ngo Nguyen 2021 年 4 月 19 日 5:36
You can use determinants to calculate the area of any polygons.
For example:
function S = areaGate(P)
S = 0;
for i = 1:length(P)-1
S = S + det(P(i:i+1,:));
end
S = abs(S)/2;

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by