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

    function cos = setOutputInfo(cos, exitflag, termmsg, OUTPUT)
%SETOUTPUTINFO Set output information for the optimization.
%   OPTIMSTORE = SETOUTPUTINFO(OPTIMSTORE, EXITFLAG, TERMMSG, OUTPUT) sets
%   output information for the optimization in OPTIMSTORE. The following
%   information is set:
%     EXITFLAG : Integer indicating why the optimization has terminated.
%                EXITFLAG > 0 implies that the optimization has terminated
%                successfully. The exit flag must be a scalar or a vector
%                with the size matching the number of solutions in the
%                optimization.
%     TERMMSG  : Termination message for optimization. The termination
%                message must be a string or a cell array of strings
%                matching the number of solutions in the optimization. 
%     OUTPUT   : Structure of algorithm statistics for the optimization.
%
%   See the worked example for an example of creating an OUTPUT structure.
%
%   This method is obsolete. Use CGOPTIMSTORE/SETEXITSTATUS and
%   CGOPTIMSTORE/SETOUTPUT instead.
%
%   See also CGOPTIMSTORE/SETEXITSTATUS, CGOPTIMSTORE/SETOUTPUT,
%   CGOPTIMSTORE/GETOUTPUTINFO

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


% Tell the user to use the SETEXITSTATUS and SETOUTPUT methods in future
if ~isv2mode(cos)
    warning(message('mbc:cgoptimstore:obsolete3'));    
end

% Convert any logical exitflags to integers 
exitflag = double(exitflag);

[ok, msg] = i_CheckInputs(cos,exitflag, termmsg, OUTPUT);

if ok
    % Ensure exitflag is an integer
    exitflag = ceil(exitflag);
    % Store results
    cos.ResultOK = exitflag;
    cos.ResultMessage = termmsg;
    cos.ResultStats = OUTPUT;
else
    error('mbc:cgoptimstore:InvalidArgument18', msg);
end

%----------------------------------------------------
function [ok, msg] = i_CheckInputs(optimstore,exitflag, termmsg, OUTPUT)
%----------------------------------------------------

ok = false;
msg = '';
NumSolutions = size(getFreeVariables(optimstore),1);
if ~isnumeric(exitflag) || ~(isscalar(exitflag) ||  NumSolutions==length(exitflag))
    msg = 'OK must be an integer.';
elseif ~ischar(termmsg) && ~(iscellstr(termmsg) && length(termmsg)==NumSolutions)
    msg = 'ERRMSG must be a string.';
elseif ~isstruct(OUTPUT)
    msg = 'OUTPUT must be a structure.';
else
    ok = true;
end