calculate area of boundary of set of 2d-data point
조회 수: 45 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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
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
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Waveform Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!