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

    function y = EvalModel(m,x,varargin)
%EVALMODEL Evaluate a model
%    Y = EVALMODEL( MODEL, X ) evaluates the model at input values X.  X is a
%    (N-by-NF) array, where NF is the number of inputs, and N the number of
%    points to evaluate the model at.
%
%    Models can also be evaluated using parentheses.
%      y = Model(X);
%
%    See also pev, predint, ceval


%  Copyright 2009-2014 The MathWorks, Inc. and Ford Global Technologies, Inc.


% check the number of inputs and outputs
narginchk(2,2);
nargoutchk(0,1);

% we are passed a numeric array - check it has the right size and convert
% to double
X = xregexportmodel.convertToDouble(x);


[~,ng]= size(m.OpPoints);
doActiveFactors = ~isempty(m.ActiveFactors);

% divide into local and operating points
if doActiveFactors 
    Xlocal = X;
else
    Xlocal = X(:,1:end-ng);
end
Xop = X(:,end-ng+1:end);

Neval = size(X,1);


% default value for output
OpPointIndices = findOpPoints(m,Xop);
uniqueOpPoints = unique(OpPointIndices);
if isscalar(uniqueOpPoints) && uniqueOpPoints~=0
    if doActiveFactors
        Xlocal = Xlocal(:,m.ActiveFactors{uniqueOpPoints});
    end
    y = EvalModel(m.ModelList,uniqueOpPoints,Xlocal);
else
    % multiple operating points
    Models = m.ModelList.Models;
    y = NaN(Neval,1);
    % remove zero 
    uniqueOpPoints(uniqueOpPoints==0)=[];
    for i = 1:length(uniqueOpPoints)
        % find current operating point
        thisOpPoint = uniqueOpPoints(i);
        CurrentOp= thisOpPoint==OpPointIndices;
        if any(CurrentOp)
            if doActiveFactors
                xi = Xlocal(CurrentOp,m.ActiveFactors{thisOpPoint});
            else
                xi = Xlocal(CurrentOp,:);
            end
            % select model and evaluate
            y(CurrentOp) = EvalModel(Models{thisOpPoint},xi);
        end
    end
end