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

    function [Xf,Yf,OK,badIndex]= checkdata(L,X,Y,Lreal)
%CHECKDATA check X and Y data for fitting

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



if nargin>3
   % 'overloaded' checkdata call
   L= Lreal;
end

% Set zeros and negative numbers to be bad data
% transform data
if HasTransform(L)
    Yd= ytrans(L,double(Y));
    % check that the inverse transform works for output data
    Yi = CalcYinv(L,Yd);
    BadTrans = abs(double(Y)-Yi)>sqrt(eps(double(Y)));
    % now do ytrans
    Y(:,1)= Yd;
else
    Yd = double(Y);
    BadTrans = false;
end

% Yd= double(Y);
Xd= code(L,double(X));
X(:,1:end)= Xd;

% reject nonfinite data and data where the inverse function doesn't work
badIndex= ~all(isfinite(Xd),2) | ~isfinite(Yd) | BadTrans;

% remove any complex data
if ~isreal(Xd)
   badIndex= badIndex | any(isSignificantImaginaryPart(Xd),2);
end
if ~isreal(Yd)
   badIndex= badIndex | isSignificantImaginaryPart(Yd);
end
   
% see if whole sweeps removed by this check
tn= testnum(Y);

Yf=  Y(~badIndex,:);
Xf=  X(~badIndex,:);

% see if whole sweeps removed by this check
% list of sweeps
OK= ismember(tn,testnum( Yf ));

function result = isSignificantImaginaryPart(val)
result = abs(imag(val)>sqrt(eps(val)));