www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@mdev_local/multimodel.m

    function m = multimodel(mdev,conModel)
%MULTIMODEL make a point-by-point model for local node
%
% m = multimodel(mdev);

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

[LocalMap,OK] = iGetLocalModel(mdev);

if any(OK)
    if ~iscell(LocalMap)
        LocalMap = {LocalMap};
    end
    X = getdata(mdev,'FIT');
    if ~all(OK)
        % make a null model to fill any gaps otherwise point-by-point
        % models could be out of sync with point-by-point boundary models
        NullModel = xregCreateModel(@xregnullmodel,model(mdev));
        LocalMap(~OK) = { NullModel };
    end
    
    T = mdevtestplan(mdev);
    Inputs = getInputs(T);
    R = [getcode(Inputs{1});getcode(Inputs{2})];
    G= model( T );
    
    Xg =  X{end};
    % only keep last of nonunique points
    [~,KeepLast]= uniqueFilters(Xg);
    LocalMap = LocalMap(KeepLast);
    ModelInfo= exportinfo(info(project(mdev)),address(mdev),[]);
    
    m = mbcPointByPointModel(LocalMap,double(Xg(KeepLast,:)),G,getname(LocalMap{1}),ModelInfo);
    % update local range
    m = setranges(m,R');
    
    if nargin<2
        conModel = BoundaryModel(T);
        if isa(conModel,'conswitch')
            conModel = syncToModel(conModel,m);
        end
    end
    m = setconstraints(m,conModel);
    
else
    m = [];
end


function [LocalMap,OK] = iGetLocalModel(mdev)


L = model(mdev);
if isPointByPoint(mdev) 
    % fast implementation for localmulti
    [X,Y]= getdata(mdev);
    Ns = size(X,3);
    LocalMap= cell(1,Ns);
    mdefault = get(L,'currentmodel');
    OK = mdev.FitOK;
    
    for i=1:Ns
        if OK(i)
            Lf = updateExportModel(L,mdev.AllModels(:,i),X(:,:,i),Y(:,:,i));
        else
            Lf = mdefault;
        end
        LocalMap{i}= Lf;
    end
else
    [LocalMap,OK] = LocalModel(mdev,':');
end