# Plotting data only inside polygon in MATLAB?

We can plot data with polygon in MATLAB as a data size of 651*1200*12 S.X and S.Y shows the X and Y values of polygon.

``````for i = 1:12
subplot(4,3,i)
pcolor(lon1,lat1,data(:,:,i)) ;
geoshow([S.Y], [S.X],'Color','black');
drawnow
axis tight
end;
``````

This method plots the all data both in and outside polygon but I have to plot data only inside the polygon. So how we can plot the data only inside polygon and put specific colour(white/black/green etc) to area outside the polygon.

The above is the output of my way.

Yet, I want to get this kind of plot: Only plot the data inside polygon with least gap between subplots both by row and column.

• Looks like raster data to me. Cant you overlay the data with a white non-transparent ocean polygon? – BERA Feb 18 at 7:43
• it is point data extracted from netcdf format and we can overlay the data with any polygon of same projection but I want to plot the data only inside polygon. – irfan Feb 18 at 7:52

I found the way to plot the point only inside polygon

``````S = shaperead(polygon);
N = length(S);
[X,Y] = meshgrid(lon1,lat1);
data= test;
for k = 1:N
idx =  insidepoly(X(:),Y(:),S(k).X,S(k).Y);
hold on
plot(X(idx), Y(idx), 'r*')
end
``````

Yet, I am trying to make same plot with respect to intensity of data value. I need to plot the value(1-100) of data with unique colour , something like jet(256) e.t.c. Looking for guidelines in this regard.