www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregmodel/fitmodel.m

    function [m,OK,S,varargout]=fitmodel(m,X,Y,varargin)
%FITMODEL Obtain least squares estimate of model
%
% [m,OK]= FITMODEL(M0,X,Y)
%  fit of model. The main tasks of fitmodel are
%    convert data to double
%    remove bad data
%    perform X and Y transformations
%
% Inputs    M0        Initial Model
%           X         column-wise X data matrix
%           Y         column-wise Y data vector
%
% Outputs   M     estimate of model
%           OK    solution found
%           S     summary statistics (labels in colhead(m))
%

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


% transform and Remove Bad Data
if ~isempty(varargin)
    [x,y,varargin{:},OK]= checkdata(m,X,Y,varargin{:});
else
    [x,y]= checkdata(m,X,Y);
end

if isempty(y)
    % nothing to fit
    OK= false;
    varargout= cell(1,nargout-3);
else
    % call the fit method
    [m,OK,varargout{1:nargout-3}]= runfit(m,x,y,varargin{:});
end

if OK>0
    % summary stats
    S = FitSummary(m,x,y);
else
    % set all stats to NaN
    S = NaN(size(StatsList(m)));
end