Main Content

regions

R2026b

Access polyshape regions

Description

polyout = regions(polyin) returns a vector of polyshape objects whose elements are the solid regions of the input polyshape.

example

Examples

collapse all

Compute a polygon with two solid regions. Then, create a vector whose elements are a single region of the polygon.

P = [0 0; 0 2; 2 2;
     2 0; NaN NaN; 0.5 0.5;
     0.5 1.5; 1.5 1.5; 1.5 0.5;
     NaN NaN; 3 0.5; 3.5 1.5;
     4 0.5; NaN NaN; 3.25 0.6;
     3.75 0.6; 3.5 1];
polyin = polyshape(P);
plot(polyin)
xlim([-0.5 4.5])
ylim([-0.5 2.5])

Polygon with two regions: a square with a square hole on the left, and a triangle with a triangular hole on the right

polyout = regions(polyin)
polyout = 
  2×1 polyshape array with properties:

    Vertices
    NumRegions
    NumHoles

plot(polyout(1))
xlim([-0.5 4.5])
ylim([-0.5 2.5])

First region of the polygon: a square with a square hole

plot(polyout(2))
xlim([-0.5 4.5])
ylim([-0.5 2.5])

Second region of the polygon: a triangle with a triangular hole

Input Arguments

collapse all

Input polyshape, specified as a scalar.

Data Types: polyshape

Tips

regions checks for regions or holes with zero enclosed area among the posyshape regions. If the functions detects any such regions or holes, it issues a warning and removes them from the resulting regions.

Version History

Introduced in R2017b