Display data ONLY inside closed polygons

6 views (last 30 days)
Hi there!
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).
Thank you!

Accepted Answer

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;
  1 Comment
Abdul Kadir Alhamid
Abdul Kadir Alhamid on 1 Aug 2020
So the function to do this is inpolygon? Great! thanks for your help.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!