www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@xregdesign/roundfactor.m

    function des = roundfactor(des, factind, method, opt)
%ROUNDFACTOR Round design points
%
%  OUT = ROUNDFACTOR(DES, FACTIND, METHOD, OPT) rounds the values in the
%  FACTIND-th column of the design.  METHOD can be either 'sigfig' or
%  'nearest'.  
%  If method is 'sigfig', OPT is the number of significant figures to round
%  the data to.
%  If method is 'nearest', OPT is the interval to round to, for example
%  OPT=50 rounds to the nearest of 0, 50, 100, 150, etc.  If OPT is a
%  2-element vector then the second element is taken as an offset, for
%  example OPT = [50 10] rounds to the nearest 10, 60, 110, etc.

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


% Only edit the non-fixed points
freep = freepoints(des);
data = des.design(freep, factind);
data = invcode(model(des), data, factind);
switch method
    case 'sigfig'
        % Round each number to intervals that are powers of 10.  The power
        % is decided by log-ing the data to decide its magnitude
        if opt<1
            error(message('mbc:xregdesign:InvalidArgument3'));
        end
        nonzerodata = (data~=0);
        interval = 10.^(floor(log10(abs(data(nonzerodata))))-opt+1);
        data(nonzerodata) = interval.*round(data(nonzerodata)./interval);
    case 'nearest'
        if opt(1)<=0
            error(message('mbc:xregdesign:InvalidArgument4'));
        end
        
        % Check whether a shift has been passed in
        if isscalar(opt)
            shift = 0;
        else
            shift = opt(2);
            opt = opt(1);
        end

        data = opt.*round((data-shift)./opt) + shift;
    case 'tolevels'
        data = interp1(opt, opt, data, 'nearest', 'extrap');
        
end
data = code(model(des), data, factind);
des.design(freep, factind) = data;

des.designindex(freep) = 0;
des.designstate = des.designstate + 1;
des = DesignType(des,0,[]);
des = timestamp(des,'stamp');