www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptimstore/private/pGetItemIndex.m
function indx = pGetItemIndex(optimstore, reqLabels, type) %PGETITEMINDEX Return the index of specified items % % INDX = PGETITEMINDEX(OPTIMSTORE, REQLABELS) returns the index of % specified items in the specified optimization list. If any items cannot % be found then this method will error. % % Copyright 2005-2006 The MathWorks, Inc. and Ford Global Technologies, Inc. switch lower(type) case 'objective' refLabels = getObjectives(optimstore); typeStr = 'objectives'; case 'constraint' refLabels = getConstraint(optimstore); typeStr = 'constraints'; case 'nonlinearconstraint' refLabels = getNonlcon(optimstore); typeStr = 'nonlinear constraints'; case 'linearconstraint' refLabels = getLcon(optimstore); typeStr = 'linear constraints'; end [nn, indx] = ismember(reqLabels, refLabels); zeroInds = find(~indx); if ~isempty(zeroInds) headstr = ['Cannot find the following ', typeStr, ... ' in the optimization: ', char(10)]; namestr = char(reqLabels(zeroInds)); namestr = [namestr, repmat(char(10), size(namestr, 1), 1)]; namestr = namestr'; str = [headstr, namestr(:)']; error('mbc:cgoptimstore:InvalidArgument', str); end