www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptim/getItem.m
function pItem = getItem(optim, label, type) %GETITEM Get the pointer to the item that is matched to a given label % % PITEM = GETITEM(OPTIM, LABEL, TYPE) returns the pointer to the item that % is currently matched to the string LABEL in the optimization. This % pointer may be null if no item has yet been matched. TYPE may be a % string or cell array of strings that specifies which types of item to % look in. If it is omitted, all types are checked. % % Valid settings for TYPE are 'variable', 'objective', 'constraint', % 'operatingpointset' or 'operatingpointsetvariable'. % Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin<3 type = {'variable', ... 'objective', ... 'constraint', ... 'operatingpointset', ... 'operatingpointsetvariable'}; elseif ~iscell(type) type = {type}; end opts = getSetup(optim); pItem = []; FindIndex = ischar(label); idx = label; for n = 1:length(type) switch lower(type{n}) case 'variable' if FindIndex idx = getVariableIndex(opts, label); end if idx>0 pItem = optim.values(idx); end case 'objective' if FindIndex idx = getObjectiveIndex(opts, label); end if idx>0 pItem = optim.Objectives{idx}; end case 'constraint' if FindIndex idx = getConstraintIndex(opts, label); end if idx>0 pItem = optim.Constraints{idx}; end case 'operatingpointset' if FindIndex idx = getOperatingPointSetIndex(opts, label); end if idx>0 pItem = optim.oppoints.Datasets(idx); end case 'operatingpointsetvariable' Nops = numOperatingPointSets(opts); for m = 1:Nops if FindIndex opvallabels = getOperatingPointSetVarLabels(opts, m); idx = find( strcmp( label,opvallabels ) ); end if idx>0 pItem = optim.oppoints.Variables{m}(idx); end end end if ~isempty(pItem) break end end