'inpolygon' returns zeros logical variable (R2019b, Win10)
Show older comments
Hi,
I try to make a mask for area of ocean's basin using function inpolygon.
I have a big area with latitude from 66° to 73° (length is 420) and longitude from -5° to 18° (length is 1380):
lat = linspace(66,73,420)'; % latitude
lon = linspace(-5,18,1380)'; % longitude
[LAT,LON] = ndgrid(lat,lon); % 2-D matrix
Next, I use contourf to plot bathymetry ('z' has 420x1380 size) and choose mask border with mouse (polygon vertices):
contourf(lon,lat,z) % bathymetry
[xi,yi] = getpts(gca); % choose mask border
xi = [xi; xi(1)]; yi = [yi; yi(1)];
hold on
plot(xi, yi,'k','LineWidth',2) % polygon (mask)
So i get something like this:

Finally, I use inpolygon to check what points (grid nodes - LAT and LON) belong to this polygon. But there is no 'true' points inside (variable 'check' is zero).
mask = inpolygon (LAT, LON, xi, yi);
check = sum(sum(mask))
Anyone have any ideas how to fix this?
1 Comment
Elena Novoselova
on 2 Jul 2020
Accepted Answer
More Answers (0)
Categories
Find more on Coordinate Reference Systems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!