Display data ONLY inside closed polygons

5 Ansichten (letzte 30 Tage)
Abdul Kadir Alhamid
Abdul Kadir Alhamid am 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!

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by