polybool Command Incorrectly Gives Workspace Variables

Hello,
I have a series of polygons which overlap and the combined polygons have some holes. I want to calculate the entire area of all the polygons and ignore the holes. I combine the polygons with the polybool command and the union setting and then want to use polyarea to find the area. When I use polyarea, the result is NaN and when I started to trace the problem, I noticed that the arrays which polybool give have a max and min value in the Workspace of NaN. However, if you look at the arrays, there are no NaN's. Has anyone run into this issue? It seems as if I can't use polyarea due to these "ghost" NaN's. If you can think of a better way to find the union area please let me know.
Thanks for any help or suggestions,
Patrick

3 Comments

Even if I type min() and max() of the variables given from polybool, I don't get NaN. I'm very confused why the Workspace says NaN and subsequently why polyarea fails.
Would you be able to post some data, perhaps a .m and a .mat, to reproduce the problem? Also, which MATLAB version are you using?
My version of MATLAB is 8.1.0.604, it's R2013a. My version of the Mapping Toolbox which is where the function polybool comes from is Version 3.7.
I've attached a sample of the data called "polygonpoints.mat" which are the points that create my two polygons. The variable "xpolypoint" are the x coordinate variables ("ypolypoint" are the y), and the cells correspond to one another, e.g. cell 1 for each variable is 1 polygon.
With those variables, I simply input them into polybool and set it to union.

Sign in to comment.

 Accepted Answer

help polybool
The polygon inputs are NaN-delimited vectors, or cell arrays containing
individual polygonal contours. The result is returned using the same
form as the input.
So if you
[x, y] = polybool('union',xpolypoint(1),ypolypoint(1),xpolypoint(2),ypolypoint(2))
then because those inputs are cells you will get cell outputs, but if you use
[x, y] = polybool('union',xpolypoint{1},ypolypoint{1},xpolypoint{2},ypolypoint{2})
then those inputs are "NaN delimited vectors" that do not happen to have any NaN in them, and the outputs are NaN delimited vectors that do have NaN which mark the end of one vector and the beginning of the next.

1 Comment

That worked perfectly, thanks for your help Walter. I guess I should do a better job at reading!

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

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

Start Hunting!