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

    function [con,ok,sp,bp,status,params] = fit(con,action,opts,X,sp,bp)
%FIT fit con object
%
% [con,ok,sp,bp,status,params] = fit(con,action,opts,X,sp,bp)
%  Inputs
%    con:      con object
%    action:   'All', 'SpecialPoints', 'BoundaryPoints', or% 'Constraint'
%    opts:     fitoptions optimmgr
%    X:        data to be fitted
%    sp:       special points
%    bp:       boundary points
%
% Outputs:
%    con
%    ok:      fit status flag
%    sp       special points
%    bp       boundary points
%    status:  status structure
%    params:  local parameters matrix

%  Copyright 2008 The MathWorks, Inc. and Ford Global Technologies, Inc.

sopts = [];
bpopts = [];
fopts = [];
doSpecialPoints  = false;
doBoundaryPoints = false;
doFitConstraint  = false;

switch lower(action)
    case 'all'
        sopts = get(opts,'SpecialPointOptions');
        bpopts = get(opts,'BoundaryPointOptions');
        fopts = get(opts,'ConstraintFitOptions');
        
        doSpecialPoints  = true;
        doBoundaryPoints = true;
        doFitConstraint  = true;

    case 'specialpoints'
        sopts = opts;
        doSpecialPoints = true;
    case 'boundarypoints'
        bpopts = opts;
        doBoundaryPoints = true;
    case 'constraint'
        fopts =opts;
        doFitConstraint = true;
    otherwise
        error(message('mbc:xregbdrydev:InvalidArgument'));
end
haveSpecialPointOptions  = ~isempty(sopts );
haveBoundaryPointOptions = ~isempty( bpopts );
haveConstraintFitOptions = ~isempty( fopts);

doSpecialPoints  = doSpecialPoints  && haveSpecialPointOptions;
doBoundaryPoints = doBoundaryPoints && haveBoundaryPointOptions;
doFitConstraint  = doFitConstraint  && haveConstraintFitOptions;

% remove nonfinite data 
DataOK = all(isfinite(X),2);
X = X(DataOK,:);

ok = true;
% Fit constraint
if ok && doSpecialPoints,
    [con, sp, ok] = findSpecialPoints( con, sopts, X );
end

if ok && doBoundaryPoints,
    [con, bp, ok] = findBoundaryPoints( con, bpopts, X );
end

if ok && doFitConstraint,
    [con, ok] = fitConstraint( con, fopts, X(bp,:) );
end

if ~isempty(bp)
    % correct boundary point indices
    DataOK = find(DataOK);
    bp = DataOK(bp);
end

status.doSpecialPoints = doSpecialPoints;
status.doBoundaryPoints = doBoundaryPoints;
status.doFitConstraint = doFitConstraint;


params = [];