Main Content

polysplit

Convert line or polygon parts from vector form to cell arrays

Syntax

[latcells,loncells] = polysplit(lat,lon)

Description

[latcells,loncells] = polysplit(lat,lon) returns the NaN-delimited segments of the vectors lat and lon as N-by-1 cell arrays with one polygon segment per cell. lat and lon must be the same size and have identically-placed NaNs. The polygon segments are column vectors if lat and lon are column vectors, and row vectors otherwise.

Examples

collapse all

Create two NaN-delimited arrays in the form of column vectors.

lat = [45.6 -23.47 78 NaN 43.9 -67.14 90 -89]';
lon = [13 -97.45 165 NaN 0 -114.2 -18 0]';

Split the column vectors into individual line segment cell arrays at the NaN separators using polysplit.

[latc,lonc] = polysplit(lat,lon)
latc=2×1 cell array
    {3x1 double}
    {4x1 double}

lonc=2×1 cell array
    {3x1 double}
    {4x1 double}

Inspect the contents of the cell arrays. Note that each cell array element contains a segment of the original line.

[latc{1} lonc{1}]
ans = 3×2

   45.6000   13.0000
  -23.4700  -97.4500
   78.0000  165.0000

[latc{2} lonc{2}]
ans = 4×2

   43.9000         0
  -67.1400 -114.2000
   90.0000  -18.0000
  -89.0000         0

You can reverse the process by using the polyjoin function.

[lat2,lon2] = polyjoin(latc,lonc);

Compare the original and joined segments. By definition, the logical comparison is false for the NaN delimiters.

[lat lon] == [lat2 lon2]
ans = 8x2 logical array

   1   1
   1   1
   1   1
   0   0
   1   1
   1   1
   1   1
   1   1

Test for global equality, including NaN values.

isequaln(lat,lat2) & isequaln(lon,lon2)
ans = logical
   1

Version History

Introduced before R2006a