MATLAB: Different color for saturated pixels in colormap

climcontourplotjetsaturation

I have a contourplot using the jet colormap. When I set the max and min data points, using the 'CLim' property, the data points above and below the limiting values are mapped on to the max and min color values respectively (right plot).
My question is, would it be possible to set the saturated pixels, the dark red and dark blue ones on the right plot, to a different color? For example saturation beyond the max value to white and below the min value to black.
Thanks!

Best Answer

Yes, just set the first and last rows to black and white
% Create sample data and display it.
indexedImage = -3E-4 * rand(50,50);
imshow(indexedImage, [], 'InitialMagnification', 800);
movegui('northeast');
% Create/initialize default colormap of jet.
cmap = jet(16); % or 256, 64, 32 or whatever.
% Now make lowest values show up as black.
cmap(1,:) = 0;
% Now make highest values show up as white.
cmap(end,:) = 1;
% Apply colormap. Changes take effect only when you call colormap().
colormap(cmap);
colorbar;