www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/@mctree/name.m
function N= name(T,newname) %NAME Set or get the node's name. % % NODENAME = NAME( NODE ) gets the name of the node % NODE = NAME( NODE, NEWNAME ) sets the node's name to NEWNAME % Copyright 2000-2008 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin==1 N=T.Name; else p= T.Parent; if p~=0 % make sure name is not shared with other siblings AllNames= p.children('name'); c=childindex(T); AllNames(c)=[]; BaseName=newname; % find pattern name(int) tok=regexp(newname,'(.*?)\(\d+\)$','tokens'); if ~isempty(tok) % base name is captured in token BaseName = tok{1}{1}; end % find next counter ind=1; while ismember(newname,AllNames); newname=[BaseName,'(',int2str(ind),')']; ind = ind+1; end end T.Name= newname; pointer(T); N=T; end