# Display data ONLY inside closed polygons

14 ビュー (過去 30 日間)
Abdul Kadir Alhamid 2020 年 8 月 1 日
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!

サインインしてコメントする。

### 採用された回答

jonas 2020 年 8 月 1 日
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 件のコメント表示非表示 なし
Abdul Kadir Alhamid 2020 年 8 月 1 日
So the function to do this is inpolygon? Great! thanks for your help.

サインインしてコメントする。

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by