フィルターのクリア

Use a custom baseline to calculate area of a graph

14 ビュー (過去 30 日間)
Rahul Ramesh
Rahul Ramesh 2021 年 6 月 4 日
コメント済み: Star Strider 2021 年 6 月 7 日
Hi,
I am a beginner level Matlab user. I tried searching the forum, could not find a working answer for this quesiton
I have this graph of Heat Flow vs Time. I need to calculate the mathematical area (Area above the baseline being positive and area below being negative) under the curve with a straight baseline formed between first and the last x-value (which is user defined) as shown in the figure below. At present, i am using the following code
%this limit we defined before is passed on to the trapz function to
lims = (x2_values >=value_of_interest_1)&(x2_values <=value_of_interest_2);
%perform numerical integration using the trapeoidal method
net_heat_flow = trapz(x2_values(lims), y2_values(lims));
However, this code calculates the area based on zero baseline. So, my question is how can i define a custom baseline as a straight line formed between the two points of interest? Can this be done using Matlab?
The figure below is from custom software I am using. However, I am trying to use Matlab for this because there are over 500 data files i need to process.
Thanks. Any help or suggestion is appreciated.

採用された回答

Star Strider
Star Strider 2021 年 6 月 4 日
Use trapz to calculate the area under the curve, and use trapz separately to calculate the area under the line.
Then subtract them.
Example —
x = linspace(0,10); % X-Vector
y = 2.5*sinc(x-5) - 0.2*x; % Y-Vector
sincarea = trapz(x, 2.5*sinc(x-5)) % Area Under Original Curve (Reference)
sincarea = 2.5997
yarea = trapz(x,y) % Area Under Displayed Curve
yarea = -7.4003
linearea = trapz(x, -0.2*x) % Area Under The Line
linearea = -10
curvearea = yarea - linearea % Area Between Line And Curve
curvearea = 2.5997
figure
plot(x, y)
hold on
plot(x, -0.2*x)
hold off
grid
axis('equal')
.
  2 件のコメント
Rahul Ramesh
Rahul Ramesh 2021 年 6 月 7 日
@Star Strider thanks for the suggestion. I did not think of this. It seems to work for mathematical area as well as absolute area. Am i correct?
Star Strider
Star Strider 2021 年 6 月 7 日
My pleasure!
If I understand your comment correctly, yes.
It returns the area between the x-axis (at y=0) and the line as ‘linearea’, and the area between the x-axis and the curve as ‘yarea’ separately, then subtracts them to return ‘curvearea’. (The ‘sincarea’ calculation is not necessary for the code, other than serving as a sort of ‘proof’ tthat the code returns the correct result.)
.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by