calculate area of boundary of set of 2d-data point
31 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/170000/image.png)
0 commentaires
Réponse acceptée
Roger Stafford
le 7 Fév 2018
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 commentaires
Niklas Kurz
le 15 Juil 2020
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.
Plus de réponses (1)
Mehdi Mosafer
le 1 Nov 2018
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 commentaires
Voir également
Catégories
En savoir plus sur Waveform Generation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!