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

    function [y,varargout]=EvalModel(m,x,varargin)
%EVALMODEL evaluate model (with coding and yinv)
% 
% [y,varargout]=EvalModel(m,x,varargin);

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


% X could be a sweepset 


nf=  nfactors(m);
if size(x,2)~=nf
	error(message('mbc:xregmodel:InvalidSize'))
end

if iscell(x)
    len= cellfun(@numel,x);
    N= len(len~=1);
    if isempty(N) 
        N = 1;
    elseif all(N==N(1))
        N = N(1);
    else
        error(message('mbc:xregmodel:InvalidSize1'))
    end
    X= zeros(N,nf);
    if N>0
        for i=1:nf
            % code element at a time to speed up coding for scalar inputs
            X(:,i)= code(m,x{i}(:),i);
        end
    end
else
    X= code(m,double(x));
end


S= varargin;
for i=1:length(S)
    S{i}= double( S{i} );
end
if nargout>1
   [y,varargout{1:nargout-1}] = eval(m,X,S{:});
else
   y= eval(m,X,S{:});
end

% invert any y transformation
y = yinv(m,y);


if ~isreal(y)
	y(abs(imag(y))>eps)= NaN;
	y =real(y);
end