Home > utils > data2cmap.m

data2cmap

PURPOSE ^

cmap_idx = data2cmap(data,map_size,prop_abs);

SYNOPSIS ^

function cmap_idx = data2cmap(data,map_size,clim)

DESCRIPTION ^

 cmap_idx = data2cmap(data,map_size,prop_abs);

 Converts data into colormap indices

 map_size is the number of rows in the colormap (default: 64)
 clim gives the endpoints of the scale (default: [min(data(:)) max(data(:))])

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cmap_idx = data2cmap(data,map_size,clim)
0002 % cmap_idx = data2cmap(data,map_size,prop_abs);
0003 %
0004 % Converts data into colormap indices
0005 %
0006 % map_size is the number of rows in the colormap (default: 64)
0007 % clim gives the endpoints of the scale (default: [min(data(:)) max(data(:))])
0008 
0009 % 12/1/04 PJ
0010 
0011 try map_size(1); catch map_size = 64; end;
0012 try clim(1); catch clim = []; end;
0013 
0014 % Determine the colormap scaling
0015 if isempty(clim)
0016   cscale = linspace(min(data(:)), max(data(:)), map_size);
0017 else
0018   cscale = linspace(clim(1),clim(2),map_size);
0019 end
0020 
0021 [count,bin_idxs] = histc(data(:),cscale);
0022 
0023 % Deal with out of range values
0024 bin_idxs(data < min(cscale)) = 1;
0025 bin_idxs(data > max(cscale)) = map_size;
0026 
0027 cmap_idx = reshape(bin_idxs,size(data));
0028 
0029 return

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003