AUC or trapz for irregular shape that intersects itself

7 ビュー (過去 30 日間)
Caitlin Bemis
Caitlin Bemis 2022 年 8 月 2 日
編集済み: Bruno Luong 2022 年 8 月 4 日
I am trying to figure out how to calculate area under the curve (AUC) for an irregular shape that intersects itself several times. The data is the length and force of a muscle that creates a thing called "work loops". The area inside of the loops are considered negative (clockwise directionality) and positive (counter-clockwise direcrtinality) work. If I could know both negative and positive work, that would be great. Although I will settle for overall work done or area inside.
I have used trapz, but that seems to not give me a consistent postive or negative number. Additionally, I cannot subset the data because the indexes needed to subset are not consecutive in some areas.
WL_1546Fa = readmatrix('~/Desktop/NAU LAB/Data/Rat/Experiments/1546/1546_WL.csv','Range','C23:C1427'); %this is where it is on my computer and hwat I need selected
Error using readmatrix
Unable to find or open '~/Desktop/NAU LAB/Data/Rat/Experiments/1546/1546_WL.csv'. Check the path and filename or file permissions.
WL_1546La = readmatrix('~/Desktop/NAU LAB/Data/Rat/Experiments/1546/1546_WL.csv', 'Range', 'F23:F1427'); %same here
plot(WL_1546La, WL_1546Fa); %plotting to see
trapz(WL_1546La, WL_1546Fa)
(The graph goes from left to the loop on the right and then turns back on itself to cross around 0.6 and create the other loops)

採用された回答

Bruno Luong
Bruno Luong 2022 年 8 月 3 日
編集済み: Bruno Luong 2022 年 8 月 4 日
I use data you provided on other thread (the excel is horrible to read, if you could provide the data in mat file format it's better for everyone);
The carea function returns positive when the area is counter clockwise, and vice versa. If the curve makes different loops with different orientations, it will sum them correctly as showed here
x=[0 3 3 1 1 0 0];
y=[0 0 2 2 -1 -1 0];
plot(x,y,'r');
axis([-1 4 -2 3])
axis equal
carea(x,y) % 3 = 4-1, because the right square is ccw = +4 the left square is cw= -1
ans = 3
Applied on your data
data = readtable('data.csv');
xy=table2array(data);
x=xy(:,1);
y=xy(:,2);
carea(x,y) % attached function
ans = 0.0583
  1 件のコメント
Caitlin Bemis
Caitlin Bemis 2022 年 8 月 4 日
Thank you. I am stil learning how to ask questions on here the most effectively!
This does exactly what I need.

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

その他の回答 (1 件)

Matt J
Matt J 2022 年 8 月 3 日
編集済み: Matt J 2022 年 8 月 3 日
Perhaps as follows?
p=polyshape(WL_1546La, WL_1546Fa);
Areas=area(regions(p))

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by