2024年5月31日发(作者:)

appdatacode = 'JRI__freezeColorsData';

[h, nancolor] = checkArgs(varargin);

%gather all children with scaled or indexed CData

cdatah = getCDataHandles(h);

%current colormap

cmap = colormap;

nColors = size(cmap,1);

cax = caxis;

% convert object color indexes into colormap to true-color data using

% current colormap

for hh = cdatah',

g = get(hh);

%preserve parent axis clim

parentAx = getParentAxes(hh);

originalClim = get(parentAx, 'clim');

% Note: Special handling of patches: For some reason, setting

% cdata on patches created by bar() yields an error,

% so instead we'll set facevertexcdata instead for patches.

if ~strcmp(,'patch'),

cdata = ;

else

cdata = rtexCData;

end

%get cdata mapping (most objects (except scattergroup) have it)

if isfield(g,'CDataMapping'),

scalemode = apping;

else

scalemode = 'scaled';

end

%save original indexed data for use with unfreezeColors

siz = size(cdata);

setappdata(hh, appdatacode, {cdata scalemode});

%convert cdata to indexes into colormap

if strcmp(scalemode,'scaled'),

%4/19/06 JRI, Accommodate scaled display of integer cdata:

% in MATLAB, uint * double = uint, so must coerce cdata to double

% Thanks to O Yamashita for pointing this need out

idx = ceil( (double(cdata) - cax(1)) / (cax(2)-cax(1)) * nColors);

else %direct mapping

idx = cdata;

/8/09 in case direct data is non-int (e.g. image;freezeColors)

% (Floor mimics how matlab converts data into colormap index.)

% Thanks to D Armyr for the catch

idx = floor(idx);

end

%clamp to [1, nColors]

idx(idx<1) = 1;

idx(idx>nColors) = nColors;

%handle nans in idx

nanmask = isnan(idx);

idx(nanmask)=1; %temporarily replace w/ a valid colormap index

%make true-color data--using current colormap

realcolor = zeros(siz);

for i = 1:3,

c = cmap(idx,i);

c = reshape(c,siz);

c(nanmask) = nancolor(i); %restore Nan (or nancolor if specified)

realcolor(:,:,i) = c;

end

%apply new true-color color data

%true-color is not supported in painters renderer, so switch out of that

if strcmp(get(gcf,'renderer'), 'painters'),

set(gcf,'renderer','zbuffer');

end

%replace original CData with true-color data