calculate area of boundary of set of 2d-data point

34 ビュー (過去 30 日間)
ha ha
ha ha 2018 年 2 月 7 日
コメント済み: Niklas Kurz 2020 年 7 月 15 日
Example: I wanna calculate the area of the boundary of set 2d-data as below illustration: I use the code(polyarea) as follows:
clear;clc;
x=[1;5;5;1;2];
y=[5;5;1;1;3];
plot(x,y,'.')
k = boundary(x,y);% generate boundary of data points
hold on;
plot(x(k),y(k));
A = polyarea(x,y);%calculate the area of boundary
But the result is: 12 <--- wrong???
How can I fix it?

採用された回答

Roger Stafford
Roger Stafford 2018 年 2 月 7 日
I would advise you to "close" the polygon so that the first point is the same as the last point. Otherwise, Matlab may be a bit confused as to how the polygon is defined.
x=[1;5;5;1;2;1];
y=[5;5;1;1;3;5];
  3 件のコメント
ha ha
ha ha 2018 年 2 月 7 日
編集済み: ha ha 2018 年 2 月 7 日
This is the sample code for calculating the area of boundary of set of 2d-data point:
clear;clc;
x=[x1;x2;x3;x4;x5;.....;xn];
y=[y1;y2;y3;y4;y5;.....;yn];
plot(x,y,'.')
k = boundary(x,y);% generate boundary of data points. %this is index of all point located in the boundary
hold on;
plot(x(k),y(k));
X=x(k);Y=y(k);%return the original x,y coordinate corresponding to each index k
A = polyarea(X,Y);%calculate the area of boundary
Niklas Kurz
Niklas Kurz 2020 年 7 月 15 日
I like you! You allowed me a second, highly valuable perspective on this issue. Even posted on my date of birth. So it was just destined to be.

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

その他の回答 (1 件)

Mehdi Mosafer
Mehdi Mosafer 2018 年 11 月 1 日
There is a simpler way; just get the 2nd output of the function "boundary:"
[k,A] = boundary(x,y)
Here, "A" is the area.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by