www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgsurfview/@svdata/getDataRange.m

    function range = getDataRange(obj,ind,trim)
%GETDATARANGE Returns the maximum and minimum values in the data
%
% range = obj.getDataRange(ind,trim)
%
% If "ind" is supplied and not empty, only the data sets at the
% specified indices are considered.
% If "trim" is supplied and true, and any constraint options are on, the
% returned range does not include data outside the boundary.
%

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


if nargin<3
    trim = false;
end

if nargin<2 || isempty(ind)
    ind = find(hasData(obj));
end

if numel(obj.rangeindices)==numel(ind)...
        && all(obj.rangeindices(:)==ind(:)) && obj.rangetrim==trim
    
    range = obj.datarange;
end

range = [Inf -Inf];
for i=1:numel(ind)
    d = obj.values{ind(i)};
    if trim && any(obj.getConstraintOptions)
        % Remove points outside the boundary
        c = obj.getConstraints;
        d(c>0) = NaN;
    end
    finite = isfinite(d);
    tempmin = min( d(finite) );
    tempmax = max( d(finite) );
    if ~isempty(tempmin)
        range(1) = min( range(1), tempmin );
    end
    if ~isempty(tempmax)
        range(2) = max( range(2), tempmax );
    end
end

obj.datarange = range;
obj.rangeindices = ind;
obj.rangetrim = trim;