[931198]: wavelets / private / deleteNode.m Maximize Restore History

Download this file

deleteNode.m    24 lines (21 with data), 779 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function wt = deleteNode(nodeNo,wt)
if(~isempty(find(wt.children{nodeNo}~=0)))
error('Deleting non-leaf node!');
end
parId = wt.parents(nodeNo);
toZero = find(wt.children{parId}==nodeNo);
wt.children{parId}(toZero) = 0;
newIdx = 1:length(wt.nodes);
newIdx = newIdx(find(newIdx~=nodeNo));
wt.nodes = wt.nodes(newIdx);
%treeStruct.a = {treeStruct.a{newIdx}};
%treeStruct.origins = {treeStruct.origins{newIdx}};
wt.parents = wt.parents(newIdx);
wt.children = wt.children(newIdx);
% and all children and parents with higher idx are lessened
for ii =1:length(wt.children)
biggerIdx = find(wt.children{ii}>nodeNo);
wt.children{ii}(biggerIdx) = wt.children{ii}(biggerIdx)-1;
end
biggerIdx = find(wt.parents>nodeNo);
wt.parents(biggerIdx) = wt.parents(biggerIdx)-1;