Display data ONLY inside closed polygons
12 views (last 30 days)
Abdul Kadir Alhamid on 1 Aug 2020
I have a quiite unique problem.I have a data of elevation in particular area, and able to display it using pcolor (the xy coordinates and data were given).Also, I have a shape file consist of this a particular city border, and able to display its border lines it using shaperead and mapshow (the x and y coordinates also given as a form of struct).
My question is, how can I display the pcolor data mentioned above ONLY inside the closed region of this polygons (in other words, display the data only inside the city, and assign the rest as NaN).
jonas on 1 Aug 2020
Super simple if you have X,Y,Z with Z being elevation as well as a closed polygon defined by xp and yp
%some sample data
[X,Y] = meshgrid(0:100,0:100);
Z = X+Y;
xp = [20,50,50,20];
yp = [20,20,50,50];
%find pts inside and remove
in = inpolygon(X(:),Y(:),xp,yp);
Z(~in) = NaN;