


PURPOSE: scale colormap to fit range of input data
-------------------------------------------------------------------
USAGE: m = scale_cmap(cmap,x)
where: cmap is the colormap to scale
data is the data to scale the colormap to, can be either vector,
matrix, or [min max] values
s is the stepsize for the interpolation, default=1 (optional)
returns colormap m of size [max(x)-min(x) 3]
-------------------------------------------------------------------
EXAMPLE: m = scale_cmap(jet,[1 500],1);
NOTES:
Felix Hebeler, Geography Dept., University Zurich, Jan 2008.
v 0.5

0001 function m = scale_cmap(cmap,data,s) 0002 % PURPOSE: scale colormap to fit range of input data 0003 % ------------------------------------------------------------------- 0004 % USAGE: m = scale_cmap(cmap,x) 0005 % where: cmap is the colormap to scale 0006 % data is the data to scale the colormap to, can be either vector, 0007 % matrix, or [min max] values 0008 % s is the stepsize for the interpolation, default=1 (optional) 0009 % returns colormap m of size [max(x)-min(x) 3] 0010 % ------------------------------------------------------------------- 0011 % EXAMPLE: m = scale_cmap(jet,[1 500],1); 0012 % 0013 % NOTES: 0014 % 0015 % Felix Hebeler, Geography Dept., University Zurich, Jan 2008. 0016 % v 0.5 0017 if ~exist('s','var') 0018 s=1; 0019 end 0020 % get min/max of input data 0021 xmin=min(data(:)); xmax=max(data(:)); 0022 % create vector using the minimum and maximum x input values and stepsize 0023 % related to the length of the input colormap 0024 x=xmin:(xmax)/size(cmap,1):xmax; 0025 size(x) 0026 y=cmap(:,1); 0027 size(y) 0028 m1=interp1(x,y,xmin:s:xmax,'linear'); 0029 y=cmap(:,2); 0030 m2=interp1(x,y,xmin:s:xmax,'linear'); 0031 y=cmap(:,3); 0032 m3=interp1(x,y,xmin:s:xmax,'linear'); 0033 m=rot90([m1; m2; m3],3);