www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptim/copyinitialvaluedata.m

    function obj = copyinitialvaluedata(obj, pValue, runDest, runSrc)
%COPYINITIALVALUEDATA Set value data
% 
%   COPYINITIALVALUEDATA(OPTIM, PVALUE, RUN, RUNSRC) sets the initial data
%   in the runs, RUNSRC, as the value to use for the variable PVALUE for
%   the runs RUN when the optimization runs.  If PVALUE is a fixed variable
%   then the data will be that variable's value for the run.  IF PVALUE is
%   a free variable then the data will be that variable's start point for
%   the run.
%  
%   There are two possible combinations for RUN and RUNSRC. RUNSRC can be
%   the number of a single run or a vector of run numbers of the same
%   length as RUN.

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


% Ensure the run numbers are column vectors
runDest = runDest(:);
NDEST = length(runDest);
runSrc = runSrc(:);
NSRC = length(runSrc);

% Sanity check on run numbers
numRunOptim = getNumRuns(obj);
if NSRC > 1 && NDEST~=NSRC
    error(message('mbc:cgoptim:InvalidArgument5'));
end
if any(~ismember(runDest, 1:numRunOptim)) || any(~ismember(runSrc, 1:numRunOptim)) 
    error(message('mbc:cgoptim:InvalidArgument6'));
end

% Write the new data in for each factor
NFACS = length(pValue);
for i = 1:NFACS
    valData = getinitialvaluedata(obj, pValue(i));
    valData = valData{1};
    data = valData(runSrc, :);
    if NSRC == 1
        data = repmat(data, NDEST, 1);
    end
    obj = setinitialvaluedata(obj, pValue(i), runDest, data);
end