How to blank a grid value with a boundary file?
1 次查看(过去 30 天)
显示 更早的评论
I have a grid like the below:
[X, Y] = ndgrid([-180:0.25:179.75],[-90:0.25:89.75]);
Z = griddata(...); %on the same grid as X and Y
I also have a boundary file like the below (a lot more complicated in reality):
140 -5
140 -30
160 -30
160 -5
140 -5
How do I use the boundary file as above to only get the griddata (X1, Y1 and Z1) within the polygon and plot them onto a map as a contour like the below?
[C1, h1] = contourf (X1, Y1, Z1);
0 个评论
采纳的回答
Clayton Gotberg
2021-4-21
Use the inpolygon function to determine which points are inside the boundary you define, then replace those points which are outside with NaN.
[X, Y] = ndgrid([-180:0.25:179.75],[-90:0.25:89.75]);
Z = griddata(...); %on the same grid as X and Y
boundaries = readmatrix('boundary_file') % replace with actual boundary file
% may need to change file-reading function
boundary_x = boundaries(:,1);% x values of boundary file
boundary_y = boundaries(:,2);% y values of boundary file
in_bounds = inpolygon(X,Y,boundary_x,boundary_y);
X(~in_bounds) = NaN;
Y(~in_bounds) = NaN;
Z(~in_bounds) = NaN;
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!