pcolor video for loop with mask

4 views (last 30 days)
curoi
curoi on 4 Feb 2014
Hi,
I'm trying to create a video time series of some map data using pcolor defined by some colormap and a black mask. The data I'm using (ex: water level) is binned by domains A, B, and C that represent different areas of the map with matrix coordinates X and Y. X and Y are not evenly spaced vectors so I can't use imagesc, which I would prefer to do but contourf might also work. I've set up a double for loop with the following code that includes VideoWriter:
aviobj = VideoWriter( strcat( 'Output\Videos', 'water_level', '.avi' ) );
aviobj.FrameRate = 6;
open( aviobj );
hFig = figure( 'Visible', 'Off' );
for j = 1:size( s.time.mapts );
cla;
hold on;
ax1 = gca;
for i = 1:length(domain);
maximum( i, 1 ) = max( max( max( s.(domain{ i, 1 }).wlvl ) ) );
minimum( i, 1 ) = min( min( min( s.(domain{ i, 1 }).wlvl) ) ) );
mini = min( minimum );
h1 = pcolor( s.(domain{ i, 1 }).xcord, s.(domain{ i, 1 }).ycord, ...
squeeze( s.(domain{ i, 1 }).wlvl( :, :, j ) ) );
shading interp;
h2 = pcolor( squeeze( s.(domain{ i, 1 }).mxcord( :, :, j ) ), ...
squeeze( s.(domain{ i, 1 }).mycord( :, :, j ) ), ...
squeeze( s.(domain{ i, 1 }).mask( :, :, j ) ) );
shading interp;
set( h2, 'alphadata', squeeze( s.(domain{ i, 1 }).mask ), ...
'alphadatamapping', 'none', 'facealpha', 'flat', ...
'facecolor', 'black' );
end
caxis( [ mini maxi( k-4, 1 ) ] );
cbx = colorbar( 'Location', 'SouthOutside' );
set( cbx, 'NextPlot', 'replaceChildren' );
colormap( squeeze( cmap( 1:(end-1), :, k-4 ) ) );
set( ax1, 'XLim', [ 200000 340000 ], 'XTick', (200000:20000:340000), ...
'XTickLabel', (200:20:340), ...
'YLim', [ 50000 140000 ], 'YTick', (50000:30000:140000), ...
'YTickLabel', (50:30:140), 'CLim', [ mini maxi( k-4, 1 ) ], ...
'NextPlot', 'replaceChildren' );
xlabel( ax1, 'X (km)' );
ylabel( ax1, 'Y (km)' );
xlabel( cbx, strcat( titlestr{ k-4, 1 }, unitsstr{ k-4, 1 } ) );
box on;
title( { strcat( titlestr{ k-4, 1 }, ' for Medium Flow: 7,000 cms' ); ...
'July 31 - Sept. 1, 2005 (dt = 2 hrs.)' } );
img = hardcopy( hFig, '-dzbuffer', '-r0' );
writeVideo( aviobj, im2frame(img) );
delete( cbx );
end
close(aviobj);
clear aviobj hFig
The problem is that only the last domain gets a black mask applied using the alphadatamapping properties. I've also tried just applying this code for the h1 pcolor plot with the same result. Alternatively, I tried adding black to the end of the colormap and specifying caxes, which works except that black ends up showing up the colorbar. I don't want that. The other thing I tried was to generate another invisible axes (ax2) and plot the mask overtop the data using NaNs for anything not masked but that also seemed not to work. Is there a simple way of applying a mask for loop to pcolor or preferably imagesc-like matrix coordinate data for all three areas of the map? FYI, the k index referes to the property being mapped (i.e. water level).
Thanks

Answers (0)

Community Treasure Hunt

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

Start Hunting!