www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgprojconnections/find.m
function items= find(Proj,varargin) %FIND search major items for name and type % % items= find(Proj,Property,value) % % Property: 'name', 'type' , 'data', 'node' , 'pointer' % type values CageTypes(cgprojconnections) % Copyright 2005 The MathWorks, Inc. fnd= Proj.IsMajorItem; pDD= getdd(info(Proj.Project)); pVars= listptrs(pDD.info); if ~isempty(pVars) AliasList= pveceval(pVars,@getaliaslist); else AliasList= {}; end for i=1:2:nargin-1 Property= varargin{i}; Value= varargin{i+1}; switch lower(Property) case 'name' if ~iscell(Value) Value= {Value}; end OK= ismember(Proj.Names,Value); if ~all(OK) % look in alias list NotFnd= find( ~ismember(Value,Proj.Names) ); AliasMatch = iFindInAliasList(Proj,pVars,AliasList,Value(NotFnd)); OK(AliasMatch) = true; end case 'type' if iscell(Value) OK= ismember(Proj.Type,Value); else OK= strcmp(Proj.Type,Value); end case 'data' if length(Value)>1 OK= ismember(Proj.pData,Value); else OK= Proj.pData==Value; end case 'node' if length(Value)>1 OK= ismember(Proj.pNode,Value); else OK= Proj.pNode==Value; end case 'pointer' % either pNode or pData if length(Value)>1 OKnode= ismember(Proj.pNode,Value); OKdata= ismember(Proj.pData,Value); OK= OKnode | OKdata; else OKnode= Proj.pNode==Value; OKdata= Proj.pData==Value; OK= OKnode | OKdata; end otherwise error(message('mbc:cgprojconnections:InvalidProperty')); end fnd= fnd & OK; end items= find(fnd); function AliasMatch = iFindInAliasList(Proj,pVars,AliasList,Value) AliasMatch= zeros(size(Value)); for i=1:length(AliasMatch) j=0; Fnd = false; while ~Fnd && j<length(AliasList) j= j+1; if ~isempty(AliasList{j}) Fnd= any( strcmp(Value{i},AliasList{j}) ); end end if Fnd AliasMatch(i)= find(pVars(j)==Proj.pData); end end AliasMatch= AliasMatch(AliasMatch~=0);