I am using this line of code to plot my contour of sea surface temperature, it is a rectangular box. [C1, h1] = contourf (X, Y, Z, [0:1:35], 'LineStyle', 'none' );
How do I trim off the areas that extends to the land with a polygon?
I tried to use "patch", but it does not work well, when the plot from the Atlantic Ocean is put together with the plots from other ocean basins.
Is there a way I can set X, Y, Z values (gridded data) to be NaN for the grids that are outside the polygon?
Thank you.

댓글 수: 4

Image Analyst
Image Analyst 2014년 12월 23일
편집: Image Analyst 2014년 12월 23일
Does this require the Mapping Toolbox? If so, list it below in the "Products" section.
Leon
Leon 2014년 12월 23일
편집: Leon 2014년 12월 23일
Thank you for the replies!
No. I plotted the map using data that I downloaded somewhere else.
Image Analyst
Image Analyst 2014년 12월 23일
편집: Image Analyst 2014년 12월 23일
Is your data an RGB image? Or is it in some other form? And explain "areas that extends to the land" - how do we know which pixels are land or not land? Do you have a binary image that defines land/not-land pixels?
Leon
Leon 2014년 12월 23일
편집: Leon 2014년 12월 23일
You mean the map data? No, they are just two columns of longitude and latitude.
I have a polygon of the boundary of Atlantic Ocean. So the function "inpolygon" only works for column data, not grid data?

댓글을 달려면 로그인하십시오.

 채택된 답변

Chad Greene
Chad Greene 2014년 12월 24일

0 개 추천

If you have the mapping toolbox you can use landmask to set land values to NaN.

댓글 수: 2

Leon
Leon 2014년 12월 25일
편집: Leon 2014년 12월 25일
This is great! Thank you so much.
Is there a way I can trim more values off? For example, the areas that extends to the Pacific Ocean.
You can simply set the limits of the map when you call worldmap. Below I set the limits from 75S to 75N and 80W to 20E.
[lon,lat] = meshgrid(linspace(-179, 179, 180),...
linspace(-89.5,89.5, 180));
z = peaks(180);
z(landmask(lat,lon))=NaN;
worldmap([-75 75],[-80 20])
pcolorm(lat,lon,z)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 12월 23일

0 개 추천

Do you have the Image Processing Toolbox? If so, you can use poly2mask() to create a mask of land/not-land. Then you can mask the image.
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, class(rgbImage)));

댓글 수: 2

Leon
Leon 2014년 12월 23일
Thank you. Unfortunately, I do not have image processing toolbox.
Image Analyst
Image Analyst 2014년 12월 23일
Then you can create a binary mask with a double for loop. You can still use bsxfun() to do the masking though - that does not require the toolbox.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기

질문:

2014년 12월 23일

댓글:

2014년 12월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by