flush.m

来自「matlab数字信号处理工具箱」· M 代码 · 共 40 行

M
40
字号
function tree = flush(tree,uid)
% XMLTREE/FLUSH Flush (Clear a subtree given its UID)
% 
% tree      - XMLTree object
% uid       - array of UID's of subtrees to be cleared
%             Default is root
%_______________________________________________________________________
%
% Clear a subtree given its UID (remove all the leaves of the tree)
% The tree parameter must be in input AND in output
%_______________________________________________________________________
% @(#)flush.m                  Guillaume Flandin               02/04/10

error(nargchk(1,2,nargin));

if nargin == 1,
	uid = root(tree);
end

uid = uid(:);
for i=1:length(uid)
	 tree = sub_flush(tree,uid(i));
end

%=======================================================================
function tree = sub_flush(tree,uid)
	if isfield(tree.tree{uid},'contents')
		% contents is parsed in reverse order because each child is
		% deleted and the contents vector is then eventually reduced
		for i=length(tree.tree{uid}.contents):-1:1
			tree = sub_flush(tree,tree.tree{uid}.contents(i));
		end
	end
	if strcmp(tree.tree{uid}.type,'chardata') |...
		strcmp(tree.tree{uid}.type,'pi') |...
		strcmp(tree.tree{uid}.type,'cdata') |...
		strcmp(tree.tree{uid}.type,'comment')
		tree = delete(tree,uid);
	end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?