function handle=colorbar(loc) % COLORBAR2 - Display color bar (color scale). % COLORBAR2 creates a thinner version of COLORBAR % % COLORBAR2('vert') appends a vertical color scale to the current % axis. COLORBAR2('horiz') appends a horizontal color scale. % % COLORBAR2(H) places the colorbar in the axes H. The colorbar will % be horizontal if the axes H width > height (in pixels). % % COLORBAR2 without arguments either adds a new vertical color scale % or updates an existing colorbar. % % H = COLORBAR2(...) returns a handle to the colorbar axis. % Clay M. Thompson 10-9-92 % Copyright (c) 1984-97 by The MathWorks, Inc. % $Revision: 1.1 $ $Date: 2005/04/13 20:38:33 $ % Brian M. Schlining 19 APR 1998 % Brian M. Schlining 18 AUG 1998 % If called with COLORBAR(H) or for an existing colorbar, don't change % the NextPlot property. changeNextPlot = 1; if nargin<1, loc = 'vert'; end ax = []; if nargin==1, if ishandle(loc) ax = loc; if ~strcmp(get(ax,'type'),'axes'), error('Requires axes handle.'); end units = get(ax,'units'); set(ax,'units','pixels'); rect = get(ax,'position'); set(ax,'units',units) if rect(3) > rect(4), loc = 'horiz'; else loc = 'vert'; end changeNextPlot = 0; end end % Determine color limits by context. If any axes child is an image % use scale based on size of colormap, otherwise use current CAXIS. ch = get(gca,'children'); hasimage = 0; t = []; cdatamapping = 'direct'; for i=1:length(ch), typ = get(ch(i),'type'); if strcmp(typ,'image'), hasimage = 1; cdatamapping = get(ch(i), 'CDataMapping'); elseif strcmp(typ,'surface') & ... strcmp(get(ch(i),'FaceColor'),'texturemap') % Texturemapped surf hasimage = 2; cdatamapping = get(ch(i), 'CDataMapping'); elseif strcmp(typ,'patch') | strcmp(typ,'surface') cdatamapping = get(ch(i), 'CDataMapping'); end end if ( strcmp(cdatamapping, 'scaled') ) if hasimage, if isempty(t); t = caxis; end else t = caxis; d = (t(2) - t(1))/size(colormap,1); t = [t(1)+d/2 t(2)-d/2]; end else if hasimage, t = [1, size(colormap,1)]; else t = [1.5 size(colormap,1)+.5]; end end h = gca; if nargin==0, % Search for existing colorbar ch = get(gcf,'children'); ax = []; for i=1:length(ch), d = get(ch(i),'userdata'); if prod(size(d))==1 & isequal(d,h), ax = ch(i); pos = get(ch(i),'Position'); if pos(3)0, handle = ax; end