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

    function varargout = getSingleSolution(obj, RunIdx, SolIdx, varargin)
%GETSINGLESOLUTION Return a specific solution and run from the optimization results.
%
%  [DATA, COLNAMES] = GETSINGLESOLUTION(OBJ, RUNIDX, SOLIDX, OPTION, VALUE, ...)
%  returns the indexed solution and run from the optimization results.
%  Named option/value pairs may be specified to control the return value:
%
%    Option          |  Value description
%    ----------------+------------------------------------------------
%    OutputFormat    |  One of 'cell' or 'matrix.  When 'cell', the output
%                    |  data will be a (1-by-NItems) cell array with each
%                    |  cell containing the values for that item.
%                    |  ColNames will be a (1-by-NItems) cell array
%                    |  containing a label for each item.  When 'matrix',
%                    |  the output data will be a 1-D matrix that contains
%                    |  all of the items' data concatenated into a
%                    |  (1-by-NItemValues) array.  ColNames will be a
%                    |  (1-by-NItemValues) cell array containing an
%                    |  appropriate label for every column.
%                    |
%    OutputContents  |  A cell array containing any combination of the
%                    |  strings 'FreeVars', 'FixedVars', 'Objectives', 
%                    |  'Constraints', 'ConstraintLHS', 'ConstraintRHS' and 
%                    |  'ConstraintFeas'.  This specifies which values 
%                    |  should be present in the output data.

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


nSol = getNumSolutions(obj);
nRuns = getNumRuns(obj);
if SolIdx > 0 && SolIdx <= nSol && RunIdx>0 && RunIdx<=nRuns
    opts = pParseGetOptions(varargin{:});
    
    % Extract free variable data
    FreeData = obj.outputData;
    for n = 1:length(FreeData)
        FreeData{n} = FreeData{n}(RunIdx, :, SolIdx);
    end
    
    [varargout{1:nargout}] = pCollectData(obj, FreeData, RunIdx, opts);
else
    error(message('mbc:cgoptimoutput:InvalidIndex3'));
end