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

    function X = bringInside(con, X)
%BRINGINSIDE Move a set of points so they are all inside the constraint.
%
%  Y = BRINGINSIDE(CON, X) is the data set X but with any points outside the
%  constraint CON projected into the constraint.
%  If X(i,:) is inside the constraint, then Y(i,:) = X(i,:).
%  If X(i,:) is outside the constriant, then Y(:,i) will be the closest point to
%  X(i,:) that is inside (on the boundary of) the constraint.
%
%  See also CONTWOSTAGE, 
%           CONBASE/BRINGINSIDE, 
%           CONBASE/ISINSIDE, 
%           CONTWOSTAGE/CONSTRAINTDISTANCE.

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

% Number of points
NP = size( X, 1 );
% Local factors
LF = getLocalIndices( con );
% Global factors
GF = getGlobalIndices( con );
% Number of global model
NGM = numel( con.Global ); 

% Evaluate the global models
b = zeros( NP, NGM );
for j = 1:NGM,
    b(:,j) = EvalModel( con.Global{j}, X(:,GF) );
end

% Bring inside the points by only changing the local factors
for i = 1:NP;
    [lc, ok] = setFeatures( con.Local, b(i,:) );
    if ok,
        if isempty( con.LocalFriend ),
            X(i,LF) = bringInside( lc, X(i,LF) );
        else
            L = code( con.LocalFriend, X(i,LF) );
            L = bringInside( lc, L );
            X(i,LF) = invcode( con.LocalFriend, L );
        end
    else
        X(i,LF) = NaN;
    end
end

    

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