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

    function X = bringInside(c, 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 CONTABLE1, CONTABLE1/ISINSIDE, CONTABLE1/CONSTRAINTDISTANCE,
%    CONBASE/BRINGINSIDE.   

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

% For a CONTABLE1 the points need to be lowered (or raised) in the y-axis
% direction by their un-scaled distance
activeIndices = getActiveIndices( c );
[in, d] = xreginterp1d( c.breakcols, c.table, activeIndices, c.le, X );

yIndex = activeIndices(2);
if c.le,
    % "Less than" constraint ==> lower points
    X(~in,yIndex) = X(~in,yIndex) - d(~in);
else
    % "Greater than" constraint ==> raise points
    X(~in,yIndex) = X(~in,yIndex) + d(~in);
end

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