Changeset 925 for trunk/src/@xmltree/copy.m
- Timestamp:
- Feb 17, 2016, 12:52:48 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/@xmltree/copy.m
r723 r925 6 6 % subuid - UID of the subtree to copy 7 7 % uid - UID of the element where the subtree must be duplicated 8 %_______________________________________________________________________ 8 %__________________________________________________________________________ 9 9 % 10 % Copy a subtree to another branch 11 % The tree parameter must be in input AND in output 12 %_______________________________________________________________________ 13 % @(#)copy.m Guillaume Flandin 02/04/0810 % Copy a subtree to another branch. 11 % The tree parameter must be in input AND in output. 12 %__________________________________________________________________________ 13 % Copyright (C) 2002-2015 http://www.artefact.tk/ 14 14 15 error(nargchk(2,3,nargin)); 15 % Guillaume Flandin 16 % $Id: copy.m 6480 2015-06-13 01:08:30Z guillaume $ 17 18 19 %error(nargchk(2,3,nargin)); 20 16 21 if nargin == 2 17 22 uid = parent(tree,subuid); 18 23 end 19 24 … … 22 27 tree.tree{uid}.contents = [tree.tree{uid}.contents l+1]; 23 28 24 % pour que la copie soit a cote de l'original et pas a la fin?29 % to have the copy next to the original and not at the end? 25 30 % contents = get(tree,parent,'contents'); 26 31 % i = find(contents==uid); 27 32 % tree = set(tree,parent,'contents',[contents(1:i) l+1 contents(i+1:end)]); 28 33 29 %======================================================================= 34 %========================================================================== 30 35 function tree = sub_copy(tree,uid,p) 31 36 32 33 34 35 36 37 38 39 40 41 42 43 44 45 37 l = length(tree); 38 tree.tree{l+1} = tree.tree{uid}; 39 tree.tree{l+1}.uid = l+1; 40 tree.tree{l+1}.parent = p; 41 tree.tree{l+1}.contents = []; 42 if isfield(tree.tree{uid},'contents') 43 contents = get(tree,uid,'contents'); 44 m = length(tree); 45 for i=1:length(contents) 46 tree.tree{l+1}.contents = [tree.tree{l+1}.contents m+1]; 47 tree = sub_copy(tree,contents(i),l+1); 48 m = length(tree); 49 end 50 end
Note: See TracChangeset
for help on using the changeset viewer.