Display data ONLY inside closed polygons
3 views (last 30 days)
Show older comments
Abdul Kadir Alhamid
on 1 Aug 2020
Commented: Abdul Kadir Alhamid
on 1 Aug 2020
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!
0 Comments
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;
%polygon
xp = [20,50,50,20];
yp = [20,20,50,50];
%find pts inside and remove
in = inpolygon(X(:),Y(:),xp,yp);
Z(~in) = NaN;
%display
surf(X,Y,Z)
More Answers (0)
See Also
Categories
Find more on Map Display 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!