function f = cmapsign(n) <n> (optional) is desired number of entries default: 64 return a blue-black-red colormap. suitable for ranges like [-X X]. example: figure; imagesc(randn(100,100)); axis equal tight; colormap(cmapsign); colorbar;
0001 function f = cmapsign(n) 0002 0003 % function f = cmapsign(n) 0004 % 0005 % <n> (optional) is desired number of entries 0006 % default: 64 0007 % 0008 % return a blue-black-red colormap. 0009 % suitable for ranges like [-X X]. 0010 % 0011 % example: 0012 % figure; imagesc(randn(100,100)); axis equal tight; colormap(cmapsign); colorbar; 0013 0014 % inputs 0015 if ~exist('n','var') || isempty(n) 0016 n = 64; 0017 end 0018 0019 % constants 0020 colors = [ 0021 0 0 1 % blue 0022 0 0 0 % black 0023 1 0 0 % red 0024 ]; 0025 0026 % do it (MAYBE CONSOLIDATE THIS CODE?) 0027 f = []; 0028 for p=1:size(colors,2) 0029 f(:,p) = interp1(linspace(0,1,size(colors,1)),colors(:,p)',linspace(0,1,n),'linear'); 0030 end 0031 0032 0033 % OLD 0034 % f = colorinterpolate(colors,31,1);