Simply skipping the loop and changing the line
inmask = inpolygon(xg(:),yg(:), bx , by );
to
inmask = inpolygon(xg(:),yg(:), x(b) , y(b) );
Gives more or less the desired result. The boundary() function does not seem to capture all the corners though.
Here is a better method which works because you are working with grouped data, i.e. several measurements on the exact same depth.
data=xlsread('ctd_data.xlsx');
x=data(:,5);
y=data(:,3)*-1;
c=data(:,4);
figure(1)
scatter(x,y,30,c,'filled')
colorbar
axis tight; hold on
shading interp
ylabel('Depth (m)');
title('Temperature distribution');
figure(2)
[xg,yg] = meshgrid(min(x):0.1:max(x),min(y):0.1:max(y));
f = scatteredInterpolant(x,y,c,'linear');
vg = f(xg,yg);
[g,xd] = findgroups(x)
yd_top = splitapply(@min,y,g)
yd_bot = splitapply(@max,y,g)
yd = [yd_top;flip(yd_bot)];
xd = [xd;flip(xd)]
inmask = inpolygon(xg(:),yg(:), xd , yd );
vg(~inmask) = nan;
h = pcolor(xg,yg,vg);
h.EdgeColor = 'none';
h.FaceColor = 'interp';
colorbar
xlabel('Distance (km)');
ylabel('Depth (m)');
cheers!
Best Answer