フィルターのクリア

I need to determine the no. of loops and area under each loop from the xy plot.

2 ビュー (過去 30 日間)
Sahil Wani
Sahil Wani 2023 年 11 月 13 日
コメント済み: Mathieu NOE 2023 年 12 月 11 日
I have the x and y data. I need to calclulate total no. loops formed and area under each loop. For the refference I am attaching the figure and x.mat and y.mat files
:
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 13 日
How do you define a loop in the given figure?
Sahil Wani
Sahil Wani 2023 年 11 月 13 日
Area enclosed as shown in fig:

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

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 11 月 13 日
hello
with the help of this FEX submission, it was quite simple :
the loops are shown in color on top of your data plot
the self intersect points are shown as red diamonds markers
result is :
area = 71.3220 125.0467 132.8896
units are unknown
code :
load('x.mat')
load('y.mat')
% remove repetitive first x = 0 data at beginning
i0 = find(x<eps);
x = x(i0(end):end);
y = y(i0(end):end);
[x0,y0,segments]=selfintersect(x,y); % fex : https://fr.mathworks.com/matlabcentral/fileexchange/13351-fast-and-robust-self-intersections
figure(1)
plot(x,y,'b',x0,y0,'dr','markersize',15);
axis square
hold on
% compute area for each loop
for k = 1:numel(x0)
ind = (segments(k,1):segments(k,2));
x_tmp = x(ind);
y_tmp = y(ind);
% compute area
area(k) = trapz(x_tmp,y_tmp);
plot(x_tmp,y_tmp)
end
area
  4 件のコメント
Mathieu NOE
Mathieu NOE 2023 年 11 月 17 日
yes this is another alternative ; NB that results are quite the same , I am not sure where the small difference comes from.
I opted for trapz to get a better result (vs an Euler integral), but I don't know the method used in polyarea
Results :
area = 71.3220 125.0467 132.8896 (trapz)
area2 = 72.5056 125.3691 132.8896 (polyarea)
load('x.mat')
load('y.mat')
% remove repetitive first x = 0 data at beginning
i0 = find(x<eps);
x = x(i0(end):end);
y = y(i0(end):end);
[x0,y0,segments]=selfintersect(x,y); % fex : https://fr.mathworks.com/matlabcentral/fileexchange/13351-fast-and-robust-self-intersections
figure(1)
plot(x,y,'b',x0,y0,'dr','markersize',15);
axis square
hold on
% compute area for each loop
for k = 1:numel(x0)
ind = (segments(k,1):segments(k,2));
x_tmp = x(ind);
y_tmp = y(ind);
% compute area
area(k) = trapz(x_tmp,y_tmp);
area2(k) = polyarea(x_tmp,y_tmp);
plot(x_tmp,y_tmp)
end
area
area2
Mathieu NOE
Mathieu NOE 2023 年 12 月 11 日
hello again @Sahil Wani
do you mind accepting my answer (if it has fullfiled your expectations ) ? tx

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by