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

    function [ok, msg] = pCheckEvaluateXXXInputs(optimstore, type, X, varargin)
%PCHECKEVALUATEXXXINPUTS Check inputs for evaluateXXX methods
%
%   OK = PCHECKEVALUATEXXXINPUTS(OPTIMSTORE, TYPE, X) checks to see if X is
%   the Npoints-by-NFreeVar matrix required by evaluateObjective (TYPE =
%   'objective') or evaluateConstraint (TYPE = 'constraint').
%
%   OK = PCHECKEVALUATEXXXINPUTS(OPTIMSTORE, TYPE, X, ITEMNAMES) in
%   addition checks to see if each member of ITEMNAMES is the name of an
%   objective or constraint in the optimization.
%
%   [OK, MSG] = PCHECKEVALUATEXXXINPUTS(OPTIMSTORE, TYPE, X, ...) returns a
%   suitable error message if the input requirements are not met.

%   Copyright 2006 The MathWorks, Inc.

ok = false;
msg = '';

% Always need to check the matrix
NFREE = sum(getNumFreeVariables(optimstore));
if ~isnumeric(X) || ~isequal(size(X, 2), NFREE)
    msg = 'X must be a (Npoints-by-NFreeVar) matrix';
    return
end

if nargin > 3
    itemNames = varargin{1};
    % Ensure that the specified items are in the optimization
    switch type
        case 'objective'
            actualItems = getObjectives(optimstore);
            typestr = ['an ', type];
        case 'constraint'
            actualItems = getConstraintNames(optimstore.OptimRunner, 'all');
            typestr = ['a ', type];            
    end
    if ~iscell(itemNames)
        msg = 'ITEMNAMES must be a cell array';
        return
    end
    if ~all(ismember(itemNames, actualItems))
        msg = ['Each member of ITEMNAMES must be ', typestr];
        return
    end
end

% If here, then the inputs are OK
ok = true;