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

    function [ok, msg] = checkOptimOutput(obj, pOut)
%CHECKOPTIMOUTPUT Determine suitability of optimization results
%
%   OUT = CHECKOPTIMOUTPUT(OBJ, pOUT) determines whether the supplied
%   optimization results can be used for exporting to a target.
%
%   [OUT, MSG] = CHECKOPTIMOUTPUT(OBJ, pOUT) additionally returns an
%   error message.
%
%   Restrictions on the optimization output:
%
%   1. The optimization results can be used in the cases where the free or
%   fixed variable lengths are members of the set [1 N], where N is the
%   maximum length of a free variable. The cgoptimexport object currently
%   does not support mixed free or fixed variable lengths.

%   Copyright 2006-2009 The MathWorks, Inc.

% Check 1
nFree = getNumFreeVariables(pOut.info);
nFixed = getNumFixedVariables(pOut.info);
nVar = [nFree, nFixed];
maxVarLen = max(nVar);
if all(nVar == 1 | nVar == maxVarLen )
    ok = true;
    msg = '';
else
    ok = false;
    msg1 = ['The optimization results contain free or fixed ', ...
        'variables of different lengths.'];
    msg2 = 'Optimization results cannot be used in this case.';
    msg = sprintf('%s\n\n%s', msg1, msg2);
end