www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbcwidgets/@ColorBar/pDrawColorBar.m

    function pDrawColorBar(obj)
%PDRAWCOLORBAR Update the ColorBar's color strip
%
%  PDRAWCOLORBAR(OBJ) is called to update the colormap that is being
%  displayed.

%  Copyright 2005-2006 The MathWorks, Inc. and Ford Global Technologies, Inc.


n = size(obj.ColorMap,1);

yl = [obj.Min, obj.Max];
if ~all(isfinite(yl))
    yl = [0 1];
else
    if yl(1)>=yl(2)
        yl(1) = yl(2)-1;
    end
end

set(obj.hAxes, 'YLim', yl);

if n==0
    set(obj.hPatch,'Vertices',[],...
        'Faces',[],...
        'FaceVertexCData',[0 0 0]);
else
    verty = linspace(yl(1), yl(2), n+1);
    vertx = zeros(size(verty));
    verty = [verty;verty];
    vertx = [vertx;(vertx+1)];
    vertz = zeros(size(verty));
    vertx = vertx(:);
    verty = verty(:);
    vertz = vertz(:);

    faces = [(1:2:(2*n-1))' , (2:2:(2*n))' , (3:2:(2*n+1))' , (4:2:(2*n+2))'];
    faces = faces(:,[1 2 4 3]);

    set(obj.hPatch,'Vertices',[vertx verty vertz],...
        'Faces',faces,...
        'FaceVertexCData',obj.ColorMap);
end