www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mvgraph2d/private/pr_graphlim.m

    function pr_graphlim(gr)
%PR_GRAPHLIM Set graph limits correctly
%  Private function for sorting out correct limits on axes and colorbar.

%  Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc.


ud = gr.DataPointer.info;
tp = ud.type;
data = ud.data;

% axes limits depend on type.
switch lower(tp)
    case 'graph'
        % normal limits
        if ~isempty(data)
            minmax = ud.limits;
            % check minmax for correct size
            if length(minmax)<size(data,2)
                minmax(end+1:size(data,2)) = {0};
            elseif length(minmax)>size(data,2)
                minmax = minmax(1:size(data,2));
            end
            
            xval = get(gr.xfactor,'Value');
            if ischar(minmax{xval}) && strcmp(minmax{xval},'auto')
                xl = [];
            elseif all(minmax{xval}==0)
                xl = mbcmakelimits(data(:, xval));
            else
                xl = minmax{xval};
                if ~all(isfinite(xl)) || xl(2)<=xl(1)
                    xl = mbcmakelimits(data(:, xval));
                end
            end

            yval = get(gr.yfactor,'Value');
            if ischar(minmax{yval}) && strcmp(minmax{yval},'auto')
                yl = [];
            elseif all(minmax{yval}==0)
                yl = mbcmakelimits(data(:, yval));
            else
                yl = minmax{yval};
                if ~all(isfinite(yl)) || yl(2)<=yl(1)
                    yl = mbcmakelimits(data(:, yval));
                end
            end

        else
            xl = [0 1];
            yl = [0 1];
        end

    case {'sparse', 'image'}
        xl = [0.5 size(data,2)+0.5];
        yl = [0.5 size(data,1)+0.5];
        if xl(2)==xl(1);
            xl(2) = 1.5;
        end
        if yl(2)==yl(1);
            yl(2) = 1.5;
        end
end

if ~isempty(xl)
    % push min and max apart a smidgeon to fix a post-R12 axes bug
    delt = (xl(2)-xl(1)).*1e-10;
    xl(1) = xl(1)-delt;
    xl(2) = xl(2)+delt;
    set(gr.axes, 'XLim', xl);
else
    set(gr.axes,'XLimMode','auto');
end

if ~isempty(yl)
    % push min and max apart a smidgeon to fix an post-R12 axes bug
    delt = (yl(2)-yl(1)).*1e-10;
    yl(1) = yl(1)-delt;
    yl(2) = yl(2)+delt;
    set(gr.axes, 'YLim', yl);
else
    set(gr.axes,'YLimMode','auto');
end

if strcmpi(tp, 'image')
    % clim determined by absolute min/max of data
    clim = mbcmakelimits(data);

    % Do colorbar ticklabels
    xlim = get(gr.colorbar.axes,'XLim');
    if ~any(isnan(clim))
        set(gr.axes,'CLim',clim);
    end
    labpoints = get(gr.colorbar.axes,'XTick');
    actpoints = clim(1)+(labpoints-0.5).*(clim(2)-clim(1))./(xlim(2)-xlim(1));
    actpoints = cellstr(num2str(actpoints','%3.2f'));
    set(gr.colorbar.axes,'XTickLabel',actpoints);
end