www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@contwostage/upgrade.m

    function con = upgrade(con, m)
%UPGRADE Upgrade a constraint to have model information
%
%  CON = UPGRADE(CON, M)
%
%  For CONTWOSTAGE, the model M should be an XREGTWOSTAGE.
%
%  For old forms of the constraint, this method will take all the
%  appropriate information from the model, M, and update the
%  information in the constraint, CON. This includes updating
%  variable information and inverse coding any data stored in coded
%  units. The version number will also be updated by this method.
%
%  This method should be called from the LOADOBJ method of any object that holds
%  a constraint. Some objects may need to setup a post-load callback if they do
%  have an appropriate model at LOADOBJ time.
%
%  See also CONTWOSTAGE, CONTWOSTAGE/LOADOBJ, CONBASE/UPGRADE, XREGTWOSTAGE.

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



if con.Version < 2, 
    m = pMakeFriend( con, m );
    % Upgrade the parent
    con.conbase = upgrade( con.conbase, m );
    % Upgrade the global models
    [con,localFriend] = i_UpgradeGlobal( con, m );
    % -- The Global Model upgrade process relies on the local constraint
    %    having not been upgraded. The upgrade process for the local
    %    constraint must happen after the global upgrade
    % Upgrade the local model
    con.Local = upgrade( con.Local, localFriend );
    % Update version number
    con.Version = 2.0;
end

%------------------------------------------------------------------------------|
function [con,localFriend] = i_UpgradeGlobal( con, friend )
% Fix up the predictions the global models are making

NLF = nFactors( con.Local );  % number of local factors
Inputs = getInputs(friend);
nGlobals = length( con.Global );

if isa(friend,'xregtwostage')
    localFriend = get( friend, 'Local' );
else
    localFriend = xregCreateModel(@localpolynomial,Inputs(1:NLF));
end
% Get & set the new coding for the global models
GlobalInputs = Inputs(NLF+1:end);
for i = 1:nGlobals,
    con.Global{i} = setInputs( con.Global{i}, GlobalInputs, true );
end

% Store the friend for the local constraints
con.LocalFriend = pMakeFriend( con.Local, localFriend );

%------------------------------------------------------------------------------|
% EOF
%------------------------------------------------------------------------------|