Matlab and wet/dry masking

Discussion about analysis, visualization, and collaboration tools and techniques

Moderators: arango, robertson

Post Reply
Message
Author
drewa
Posts: 35
Joined: Mon Dec 17, 2007 5:34 pm
Location: SCCWRP, Costa Mesa, CA

Matlab and wet/dry masking

#1 Unread post by drewa »

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

User avatar
arango
Site Admin
Posts: 1367
Joined: Wed Feb 26, 2003 4:41 pm
Location: DMCS, Rutgers University
Contact:

#2 Unread post by arango »

It is very trivial. Just do:

Code: Select all

   ...
    ind=find(mask < 1);

    field=squeeze(zeta(:,:,i));
    field(ind)=NaN;
    contourf(lon,lat,field,25,'linestyle','none')
    ...
So the strategy is to fill the mask areas with NaNs. Matlab will ignore plotting those values.

drewa
Posts: 35
Joined: Mon Dec 17, 2007 5:34 pm
Location: SCCWRP, Costa Mesa, CA

#3 Unread post by drewa »

Thanks a lot. That did the trick.

Post Reply