I am trying to plot results from a wet/dry simulation via Matlab R2007b. I want a filled contour plot of zeta (show the colorbar as well), a line contour of h, and then lay mask out the dry areas. I'm a bit stuck on how to code the masking. I've tried doing a masking but I not sure on how to have no color on the wet areas without brute-forcing through a for loop and if statements each matrices. Below is my Matlab code.
thanks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[xi eta time]=size(zeta);
j=0
for i=2:time
caxis([0 1]);
colorbar
colormap(jet)
hold on
% plot results of matrix 1
contourf(lon,lat,zeta(:,:,i),25,'linestyle','none')
% plot model contours
contour(lon,lat,h,20,'k-')
% mask=0, let through =1
colorbar(gray)
surf(lon,lat,wet_dry(:,:,i),'linestyle','none','AlphaDataMapping','direct')
imgname = sprintf('zeta_%04d.jpg',j);
print('-djpeg','-r100',imgname);% print to jpeg
j=j+1;
hold off
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Matlab and wet/dry masking
- arango
- Site Admin
- Posts: 1367
- Joined: Wed Feb 26, 2003 4:41 pm
- Location: DMCS, Rutgers University
- Contact:
It is very trivial. Just do:
So the strategy is to fill the mask areas with NaNs. Matlab will ignore plotting those values.
Code: Select all
...
ind=find(mask < 1);
field=squeeze(zeta(:,:,i));
field(ind)=NaN;
contourf(lon,lat,field,25,'linestyle','none')
...