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

    function con = setActiveIndices(con, newAi)
%SETACTIVEINDICES Set the indices of the active factors for a Range Constraint
%
%  CON = SETACTIVEINDICES(CON, AI)
%
%  Old active factors that are kept will have their values preserved. New
%  active values will have their values set to the range given in the input
%  factor object.
%
%  See also CONRANGE, CONBASE/SETACTIVEINDICES, CONBASE/GETACTIVEINDICES.

%  Copyright 2000-2007 The MathWorks, Inc.

newAi = sort( newAi(:).' );
oldAi = getActiveIndices( con ); 

% Set the active indices in the parent object
con.conbase = setActiveIndices( con.conbase, newAi );

% For any new active indices, we set the min and max (via the "Center" and
% "HalfWidth") to the factor range. For any old indices that are kept, we
% keep the old values.  
cif = getActiveFactors( con );
mn = getMin( cif );
mx = getMax( cif );
newCenter    = 0.5 * (mx + mn);
newHalfWidth = 0.5 * (mx - mn);

[tf, loc] = ismember( newAi, oldAi );
newCenter(   tf) = con.Center(   loc(tf));
newHalfWidth(tf) = con.HalfWidth(loc(tf));

con.Center    = newCenter;
con.HalfWidth = newHalfWidth;
% set scale factor
con = pSetScaleFactor(con);

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