新浪博客

Matlab 冻结颜色(条)

2013-05-22 19:59阅读:


实现方法:
1、下载freezeColors_v23_cbfreeze.zip用于冻结颜色和cm_and_cb_utilities.zip用于冻结颜色条:
freezeColors_v23_cbfreeze.zip:http://www.mathworks.com/matlabcentral/fileexchange/7943
cm_and_cb_utilities.zip:http://www.mathworks.com/matlabcentral/fileexchange/24371
2、将freezeColors_v23_cbfreeze.zip里的freezeColors.m,cm_and_cb_utilities.zip里的cbfreeze.m和cbhandle.m放到你运行路径下:运行matlab,file->set path->add with subfolders.....选择你需要添加的的函数
3、测试代码:
close all
a=imread('E:\L5120036_03620070507_B10.TIF');%根据实际情况更改
%最原始的图像显示函数(主要彩色显示图象)
b=[1,2,3,4;
4,5,6,7;
8,9,10,11];
subplot(221);image(b);cbfreeze(colorbar);freezeColors;
subplot(223);imagesc(b);cbfreeze(colorbar);freezeColors;
%灰度图像文件的显示
subplot(222);imshow(a);colorbar;

或者

subplot(2,1,1)
imagesc(peaks)
colormap hot
freezeColors %freeze this plot's colormap
cbfreeze(colorbar);
subplot(2,1,2)
colormap hsv % won't change any frozen plots!
surf(peaks)
freezeColors
cbfreeze(colorbar)


PS : Contents.m
% Functions enabling use of multiple colormaps per figure.
%
% version 2.3, 3/2007
%
% freezeColors - Lock colors of plot, enabling multiple colormaps per figure.
% unfreezeColors - Restore colors of a plot to original indexed color.
%
% demo/html
% freezeColors_pub.html - Published demonstration.
%
% test
% test_main - Test function.
% AUTHOR
% John Iversen, 2005-10
% john_iversen@post.harvard.edu
%
% Free for any use, so long as AUTHOR information remains with code.
%
% HISTORY
%
% JRI 6/2005 (v1)
% JRI 9/2006 (v2.1) now operates on all objects with CData (not just images as before)
% JRI 11/2006 handle NaNs in images/surfaces (was not posted on file exchange, included in v2.3)
% JRI 3/2007 (v2.3) Fix bug in handling of caxis that made colorbar scales on frozen plots incorrect.
% JRI 4/2007 Add 'published' html documentation.
% JRI 9/2010 Changed documentation for colorbars
_______________________________________________________________________________________________________
freezeColors.m
function freezeColors(varargin)
% freezeColors Lock colors of plot, enabling multiple colormaps per figure. (v2.3)
%
% Problem: There is only one colormap per figure. This function provides
% an easy solution when plots using different colomaps are desired
% in the same figure.
%
% freezeColors freezes the colors of graphics objects in the current axis so
% that subsequent changes to the colormap (or caxis) will not change the
% colors of these objects. freezeColors works on any graphics object
% with CData in indexed-color mode: surfaces, images, scattergroups,
% bargroups, patches, etc. It works by converting CData to true-color rgb
% based on the colormap active at the time freezeColors is called.
%
% The original indexed color data is saved, and can be restored using
% unfreezeColors, making the plot once again subject to the colormap and
% caxis.
%
%
% Usage:
% freezeColors applies to all objects in current axis (gca),
% freezeColors(axh) same, but works on axis axh.
%
% Example:
% subplot(2,1,1); imagesc(X); colormap hot; freezeColors
% subplot(2,1,2); imagesc(Y); colormap hsv; freezeColors etc...
%
% Note: colorbars must also be frozen. Due to Matlab 'improvements' this can
% no longer be done with freezeColors. Instead, please
% use the function CBFREEZE by Carlos Adrian Vargas Aguilera
% that can be downloaded from the MATLAB File Exchange
% (http://www.mathworks.com/matlabcentral/fileexchange/24371)
%
% h=colorbar; cbfreeze(h), or simply cbfreeze(colorbar)
%
% For additional examples, see test/test_main.m
%
% Side effect on render mode: freezeColors does not work with the painters
% renderer, because Matlab doesn't support rgb color data in
% painters mode. If the current renderer is painters, freezeColors
% changes it to zbuffer. This may have unexpected effects on other aspects
% of your plots.
%
% See also unfreezeColors, freezeColors_pub.html, cbfreeze.
%
%
% John Iversen (iversen@nsi.edu) 3/23/05
%
% Changes:
% JRI (iversen@nsi.edu) 4/19/06 Correctly handles scaled integer cdata
% JRI 9/1/06 should now handle all objects with cdata: images, surfaces,
% scatterplots. (v 2.1)
% JRI 11/11/06 Preserves NaN colors. Hidden option (v 2.2, not uploaded)
% JRI 3/17/07 Preserve caxis after freezing--maintains colorbar scale (v 2.3)
% JRI 4/12/07 Check for painters mode as Matlab doesn't support rgb in it.
% JRI 4/9/08 Fix preserving caxis for objects within hggroups (e.g. contourf)
% JRI 4/7/10 Change documentation for colorbars
% Hidden option for NaN colors:
% Missing data are often represented by NaN in the indexed color
% data, which renders transparently. This transparency will be preserved
% when freezing colors. If instead you wish such gaps to be filled with
% a real color, add 'nancolor',[r g b] to the end of the arguments. E.g.
% freezeColors('nancolor',[r g b]) or freezeColors(axh,'nancolor',[r g b]),
% where [r g b] is a color vector. This works on images & pcolor, but not on
% surfaces.
% Thanks to Fabiano Busdraghi and Jody Klymak for the suggestions. Bugfixes
% attributed in the code.
% Free for all uses, but please retain the following:
% Original Author:
% John Iversen, 2005-10
% john_iversen@post.harvard.edu
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(g.Type,'patch'),
cdata = g.CData;
else
cdata = g.FaceVertexCData;
end

%get cdata mapping (most objects (except scattergroup) have it)
if isfield(g,'CDataMapping'),
scalemode = g.CDataMapping;
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
if ~strcmp(g.Type,'patch'),
set(hh,'CData',realcolor);
else
set(hh,'faceVertexCData',permute(realcolor,[1 3 2]))
end

%restore clim (so colorbar will show correct limits)
if ~isempty(parentAx),
set(parentAx,'clim',originalClim)
end

end %loop on indexed-color objects
% ============================================================================ %
% Local functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% getCDataHandles -- get handles of all descendents with indexed CData
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function hout = getCDataHandles(h)
% getCDataHandles Find all objects with indexed CData
%recursively descend object tree, finding objects with indexed CData
% An exception: don't include children of objects that themselves have CData:
% for example, scattergroups are non-standard hggroups, with CData. Changing
% such a group's CData automatically changes the CData of its children,
% (as well as the children's handles), so there's no need to act on them.
error(nargchk(1,1,nargin,'struct'))
hout = [];
if isempty(h),return;end
ch = get(h,'children');
for hh = ch'
g = get(hh);
if isfield(g,'CData'), %does object have CData?
%is it indexed/scaled?
if ~isempty(g.CData) && isnumeric(g.CData) && size(g.CData,3)==1,
hout = [hout; hh]; %#ok %yes, add to list
end
else %no CData, see if object has any interesting children
hout = [hout; getCDataHandles(hh)]; %#ok
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% getParentAxes -- return handle of axes object to which a given object belongs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function hAx = getParentAxes(h)
% getParentAxes Return enclosing axes of a given object (could be self)
error(nargchk(1,1,nargin,'struct'))
%object itself may be an axis
if strcmp(get(h,'type'),'axes'),
hAx = h;
return
end
parent = get(h,'parent');
if (strcmp(get(parent,'type'), 'axes')),
hAx = parent;
else
hAx = getParentAxes(parent);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% checkArgs -- Validate input arguments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [h, nancolor] = checkArgs(args)
% checkArgs Validate input arguments to freezeColors
nargs = length(args);
error(nargchk(0,3,nargs,'struct'))
%grab handle from first argument if we have an odd number of arguments
if mod(nargs,2),
h = args{1};
if ~ishandle(h),
error('JRI:freezeColors:checkArgs:invalidHandle',...
'The first argument must be a valid graphics handle (to an axis)')
end
% 4/2010 check if object to be frozen is a colorbar
if strcmp(get(h,'Tag'),'Colorbar'),
if ~exist('cbfreeze.m'),
warning('JRI:freezeColors:checkArgs:cannotFreezeColorbar',...
['You seem to be attempting to freeze a colorbar. This no longer'...
'works. Please read the help for freezeColors for the solution.'])
else
cbfreeze(h);
return
end
end
args{1} = [];
nargs = nargs-1;
else
h = gca;
end
%set nancolor if that option was specified
nancolor = [nan nan nan];
if nargs == 2,
if strcmpi(args{end-1},'nancolor'),
nancolor = args{end};
if ~all(size(nancolor)==[1 3]),
error('JRI:freezeColors:checkArgs:badColorArgument',...
'nancolor must be [r g b] vector');
end
nancolor(nancolor>1) = 1; nancolor(nancolor<0) = 0;
else
error('JRI:freezeColors:checkArgs:unrecognizedOption',...
'Unrecognized option (%s). Only ''nancolor'' is valid.',args{end-1})
end
end_________________________________________________________________________________________________
unfreezeColors.m
function unfreezeColors(h)
% unfreezeColors Restore colors of a plot to original indexed color. (v2.3)
%
% Useful if you want to apply a new colormap to plots whose
% colors were previously frozen with freezeColors.
%
% Usage:
% unfreezeColors unfreezes all objects in current axis,
% unfreezeColors(axh) same, but works on axis axh. axh can be vector.
% unfreezeColors(figh) same, but for all objects in figure figh.
%
% Has no effect on objects on which freezeColors was not already called.
% (Note: if colorbars were frozen using cbfreeze, use cbfreeze('off') to
% unfreeze them. See freezeColors for information on cbfreeze.)
%
%
% See also freezeColors, freezeColors_pub.html, cbfreeze.
%
%
% John Iversen (iversen@nsi.edu) 3/23/05
%
% Changes:
% JRI 9/1/06 now restores any object with frozen CData;
% can unfreeze an entire figure at once.
% JRI 4/7/10 Change documentation for colorbars
% Free for all uses, but please retain the following:
%
% Original Author:
% John Iversen, 2005-10
% john_iversen@post.harvard.edu
error(nargchk(0,1,nargin,'struct'))
appdatacode = 'JRI__freezeColorsData';
�fault: operate on gca
if nargin < 1,
h = gca;
end
if ~ishandle(h),
error('JRI:unfreezeColors:invalidHandle',...
'The argument must be a valid graphics handle to a figure or axis')
end
%if h is a figure, loop on its axes
if strcmp(get(h,'type'),'figure'),
h = get(h,'children');
end
for h1 = h', %loop on axes
%process all children, acting only on those with saved CData
% ( in appdata JRI__freezeColorsData)
ch = findobj(h1);

for hh = ch',

%some object handles may be invalidated when their parent changes
% (e.g. restoring colors of a scattergroup unfortunately changes
% the handles of all its children). So, first check to make sure
% it's a valid handle
if ishandle(hh)
if isappdata(hh,appdatacode),
ad = getappdata(hh,appdatacode);
%get oroginal cdata
%patches have to be handled separately (see note in freezeColors)
if ~strcmp(get(hh,'type'),'patch'),
cdata = get(hh,'CData');
else
cdata = get(hh,'faceVertexCData');
cdata = permute(cdata,[1 3 2]);
end
indexed = ad{1};
scalemode = ad{2};

%size consistency check
if all(size(indexed) == size(cdata(:,:,1))),
%ok, restore indexed cdata
if ~strcmp(get(hh,'type'),'patch'),
set(hh,'CData',indexed);
else
set(hh,'faceVertexCData',indexed);
end
%restore cdatamapping, if needed
g = get(hh);
if isfield(g,'CDataMapping'),
set(hh,'CDataMapping',scalemode);
end
%clear appdata
rmappdata(hh,appdatacode)
else
warning('JRI:unfreezeColors:internalCdataInconsistency',...
['Could not restore indexed data: it is the wrong size. ' ...
'Were the axis contents changed since the call to freezeColors?'])
end

end %test if has our appdata
end %test ishandle
end %loop on children
end %loop on axes
_____________________________________________________________________________________________________
cbfrrze.m
function CBH = cbfreeze(varargin)
�FREEZE Freezes the colormap of a colorbar.
%
% SYNTAX:
% cbfreeze
% cbfreeze('off')
% cbfreeze(H,...)
% CBH = cbfreeze(...);
%
% INPUT:
% H - Handles of colorbars to be freezed, or from figures to search
% for them or from peer axes (see COLORBAR).
% DEFAULT: gcf (freezes all colorbars from the current figure)
% 'off' - Unfreezes the colorbars, other options are:
% 'on' Freezes
% 'un' same as 'off'
% 'del' Deletes the colormap(s).
% DEFAULT: 'on' (of course)
%
% OUTPUT (all optional):
% CBH - Color bar handle(s).
%
% DESCRIPTION:
% MATLAB works with a unique COLORMAP by figure which is a big
% limitation. Function FREEZECOLORS by John Iversen allows to use
% different COLORMAPs in a single figure, but it fails freezing the
% COLORBAR. This program handles this problem.
%
% NOTE:
% * Optional inputs use its DEFAULT value when not given or [].
% * Optional outputs may or not be called.
% * If no colorbar is found, one is created.
% * The new frozen colorbar is an axes object and does not behaves
% as normally colorbars when resizing the peer axes. Although, some
% time the normal behavior is not that good.
% * Besides, it does not have the 'Location' property anymore.
% * But, it does acts normally: no ZOOM, no PAN, no ROTATE3D and no
% mouse selectable.
% * No need to say that CAXIS and COLORMAP must be defined before using
% this function. Besides, the colorbar location. Anyway, 'off' or
% 'del' may help.
% * The 'del' functionality may be used whether or not the colorbar(s)
% is(are) froozen. The peer axes are resized back. Try:
% >> colorbar, cbfreeze del
%
% EXAMPLE:
% surf(peaks(30))
% colormap jet
% cbfreeze
% colormap gray
% title('What...?')
%
% SEE ALSO:
% COLORMAP, COLORBAR, CAXIS
% and
% FREEZECOLORS by John Iversen
% at http://www.mathworks.com/matlabcentral/fileexchange
%
%
% ---
% MFILE: cbfreeze.m
% VERSION: 1.1 (Sep 02, 2009) (download)
% MATLAB: 7.7.0.471 (R2008b)
% AUTHOR: Carlos Adrian Vargas Aguilera (MEXICO)
% CONTACT: nubeobscura@hotmail.com
% REVISIONS:
% 1.0 Released. (Jun 08, 2009)
% 1.1 Fixed BUG with image handle on MATLAB R2009a. Thanks to Sergio
% Muniz. (Sep 02, 2009)
% DISCLAIMER:
% cbfreeze.m is provided 'as is' without warranty of any kind, under the
% revised BSD license.
% Copyright (c) 2009 Carlos Adrian Vargas Aguilera
% INPUTS CHECK-IN
% -------------------------------------------------------------------------
% Parameters:
cbappname = 'Frozen'; % Colorbar application data with fields:
% 'Location' from colorbar
% 'Position' from peer axes befor colorbar
% 'pax' handle from peer axes.
axappname = 'FrozenColorbar'; % Peer axes application data with frozen
% colorbar handle.

% Set defaults:
S = 'on'; Sopt = {'on','un','off','del'};
H = get(0,'CurrentFig');
% Check inputs:
if nargin==2 && (~isempty(varargin{1}) && all(ishandle(varargin{1})) && ...
isempty(varargin{2}))

% Check for CallBacks functionalities:
% ------------------------------------

varargin{1} = double(varargin{1});

if strcmp(get(varargin{1},'BeingDelete'),'on')
% Working as DeletFcn:
if (ishandle(get(varargin{1},'Parent')) && ...
~strcmpi(get(get(varargin{1},'Parent'),'BeingDeleted'),'on'))
% The handle input is being deleted so do the colorbar:
S = 'del';

if ~isempty(getappdata(varargin{1},cbappname))
% The frozen colorbar is being deleted:
H = varargin{1};
else
% The peer axes is being deleted:
H = ancestor(varargin{1},{'figure','uipanel'});
end

else
% The figure is getting close:
return
end

elseif (gca==varargin{1} && ...
gcf==ancestor(varargin{1},{'figure','uipanel'}))
% Working as ButtonDownFcn:

cbfreezedata = getappdata(varargin{1},cbappname);
if ~isempty(cbfreezedata)
if ishandle(cbfreezedata.ax)
% Turns the peer axes as current (ignores mouse click-over):
set(gcf,'CurrentAxes',cbfreezedata.ax);
return
end
else
% Clears application data:
rmappdata(varargin{1},cbappname)
end
H = varargin{1};
end

else

% Checks for normal calling:
% --------------------------

% Looks for H:
if nargin && ~isempty(varargin{1}) && all(ishandle(varargin{1}))
H = varargin{1};
varargin(1) = [];
end
% Looks for S:
if ~isempty(varargin) && (isempty(varargin{1}) || ischar(varargin{1}))
S = varargin{1};
end
end
% Checks S:
if isempty(S)
S = 'on';
end
S = lower(S);
iS = strmatch(S,Sopt);
if isempty(iS)
error('CVARGAS:cbfreeze:IncorrectStringOption',...
['Unrecognized ''' S ''' argument.' ])
else
S = Sopt{iS};
end
% Looks for CBH:
CBH = cbhandle(H);
if ~strcmp(S,'del') && isempty(CBH)
% Creates a colorbar and peer axes:
pax = gca;
CBH = colorbar('peer',pax);
else
pax = [];
end
% -------------------------------------------------------------------------
% MAIN
% -------------------------------------------------------------------------
% Note: only CBH and S are necesary, but I use pax to avoid the use of the
% 'hidden' 'Axes' COLORBAR's property. Why... ?
% Saves current position:
fig = get( 0,'CurrentFigure');
cax = get(fig,'CurrentAxes');
% Works on every colorbar:
for icb = 1:length(CBH)

% Colorbar axes handle:
h = double(CBH(icb));

% This application data:
cbfreezedata = getappdata(h,cbappname);

% Gets peer axes:
if ~isempty(cbfreezedata)
pax = cbfreezedata.pax;
if ~ishandle(pax) % just in case
rmappdata(h,cbappname)
continue
end
elseif isempty(pax) % not generated
try
pax = double(get(h,'Axes')); % NEW feature in COLORBARs
catch
continue
end
end

% Choose functionality:
switch S

case 'del'
% Deletes:
if ~isempty(cbfreezedata)
% Returns axes to previous size:
oldunits = get(pax,'Units');
set(pax,'Units','Normalized');
set(pax,'Position',cbfreezedata.Position)
set(pax,'Units',oldunits)
set(pax,'DeleteFcn','')
if isappdata(pax,axappname)
rmappdata(pax,axappname)
end
end
if strcmp(get(h,'BeingDelete'),'off')
delete(h)
end

case {'un','off'}
% Unfrozes:
if ~isempty(cbfreezedata)
delete(h);
set(pax,'DeleteFcn','')
if isappdata(pax,axappname)
rmappdata(pax,axappname)
end
oldunits = get(pax,'Units');
set(pax,'Units','Normalized')
set(pax,'Position',cbfreezedata.Position)
set(pax,'Units',oldunits)
CBH(icb) = colorbar(...
'peer' ,pax,...
'Location',cbfreezedata.Location);
end

otherwise % 'on'
% Freezes:

% Gets colorbar axes properties:
cb_prop = get(h);

% Gets colorbar image handle. Fixed BUG, Sep 2009
hi = findobj(h,'Type','image');

% Gets image data and transform it in a RGB:
CData = get(hi,'CData');
if size(CData,3)~=1
% It's already frozen:
continue
end

% Gets image tag:
Tag = get(hi,'Tag');

% Deletes previous colorbar preserving peer axes position:
oldunits = get(pax,'Units');
set(pax,'Units','Normalized')
Position = get(pax,'Position');
delete(h)
cbfreezedata.Position = get(pax,'Position');
set(pax,'Position',Position)
set(pax,'Units',oldunits)

% Generates new colorbar axes:
% NOTE: this is needed because each time COLORMAP or CAXIS is used,
% MATLAB generates a new COLORBAR! This eliminates that behaviour
% and is the central point on this function.
h = axes(...
'Parent' ,cb_prop.Parent,...
'Units' ,'Normalized',...
'Position',cb_prop.Position...
);

% Save location for future call:
cbfreezedata.Location = cb_prop.Location;

% Move ticks because IMAGE draws centered pixels:
XLim = cb_prop.XLim;
YLim = cb_prop.YLim;
if isempty(cb_prop.XTick)
% Vertical:
X = XLim(1) + diff(XLim)/2;
Y = YLim + diff(YLim)/(2*length(CData))*[+1 -1];
else % isempty(YTick)
% Horizontal:
Y = YLim(1) + diff(YLim)/2;
X = XLim + diff(XLim)/(2*length(CData))*[+1 -1];
end

% Draws a new RGB image:
image(X,Y,ind2rgb(CData,colormap),...
'Parent' ,h,...
'HitTest' ,'off',...
'Interruptible' ,'off',...
'SelectionHighlight','off',...
'Tag' ,Tag...
)
% Removes all '...Mode' properties:
cb_fields = fieldnames(cb_prop);
indmode = strfind(cb_fields,'Mode');
for k=1:length(indmode)
if ~isempty(indmode{k})
cb_prop = rmfield(cb_prop,cb_fields{k});
end
end

% Removes special COLORBARs properties:
cb_prop = rmfield(cb_prop,{...
'CurrentPoint','TightInset','BeingDeleted','Type',... % read-only
'Title','XLabel','YLabel','ZLabel','Parent','Children',... % handles
'UIContextMenu','Location',... % colorbars
'ButtonDownFcn','DeleteFcn',... % callbacks
'CameraPosition','CameraTarget','CameraUpVector','CameraViewAngle',...
'PlotBoxAspectRatio','DataAspectRatio','Position',...
'XLim','YLim','ZLim'});

% And now, set new axes properties almost equal to the unfrozen
% colorbar:
set(h,cb_prop)
% CallBack features:
set(h,...
'ActivePositionProperty','position',...
'ButtonDownFcn' ,@cbfreeze,... % mhh...
'DeleteFcn' ,@cbfreeze) % again
set(pax,'DeleteFcn' ,@cbfreeze) % and again!

% Do not zoom or pan or rotate:
setAllowAxesZoom (zoom ,h,false)
setAllowAxesPan (pan ,h,false)
setAllowAxesRotate(rotate3d,h,false)

% Updates data:
CBH(icb) = h;
% Saves data for future undo:
cbfreezedata.pax = pax;
setappdata( h,cbappname,cbfreezedata);
setappdata(pax,axappname,h);

end % switch functionality
end % MAIN loop
% OUTPUTS CHECK-OUT
% -------------------------------------------------------------------------
% Output?:
if ~nargout
clear CBH
else
CBH(~ishandle(CBH)) = [];
end
% Returns current axes:
if ishandle(cax)
set(fig,'CurrentAxes',cax)
end
% [EOF] cbfreeze.m

我的更多文章

下载客户端阅读体验更佳

APP专享