-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodeAt.m
115 lines (103 loc) · 2.45 KB
/
nodeAt.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
function node = nodeAt( tree, label )
% node = nodeGetNum( tree, label )
% Takes a tree and a label, finds the label in the tree and returns
%
% Argument:
% node - The tree
% label - The cpc label, node name, or node number
%
% Returns:
% node - The node itself
%
% author: Navid Nourani-Vatani @ ACFR
% version: 1.0 2013-08-02
node = {};
%fprintf('label='); disp( label )
%fprintf('\ttree.name=%s\n', tree.name)
found = false;
%is it a node number?
if isa( label, 'numeric' )
if tree.num == label
found = true;
end
elseif strcmpi( label, tree.name )
found = true;
else
% is the label here?
for i = 1:length(tree.labels)
if strcmpi( label, tree.labels{i} )
found = true;
break;
end
end
end
if found
node = tree;
return;
end
for i = 1:length(tree.children)
node = nodeAt(tree.children{i}, label);
if ~isempty(node)
return
end
end
% nodeList = {};
% nodeList{1} = tree;
%
% nodeNum = 0;
% nodeParent{1} = tree;
% nodeParent{1}.name = '';
% nodeParent{1}.labels = {};
% nodeParent{1}.children = {};
%
%
% found = false;
% while ~isempty(nodeList) && ~found
% nodeCurr = nodeList{nodeNum+1};
%
% if verbose == true
% fprintf( '%2d - curr: %s\n', ...
% nodeCurr.num, nodeCurr.name );
% end
%
% % is it a node number?
% if isa( label, 'numeric' )
% if nodeCurr.num == label
% nodeParent = nodeParent{nodeNum+1};
% break
% end
% else
% % is it a node name?
% if strcmpi( label, nodeCurr.name )
% nodeParent = nodeParent{nodeNum+1};
% if verbose == true
% fprintf( 'FOUND %s @ %d\n', label, nodeNum );
% end
% break;
% end
%
% % is the label here?
% for i = 1:length(nodeCurr.labels)
% if strcmpi( label, nodeCurr.labels{i} )
% found = true;
% if verbose == true
% fprintf( 'FOUND %s @ %d\n', label, nodeNum );
% end
% break;
% end
% end
% end
%
% if found
% nodeParent = nodeParent{nodeNum+1};
% break
% end
%
% for i = 1:length(nodeCurr.children)
% nodeList{end+1} = nodeCurr.children{i};
% nodeParent{end+1} = nodeCurr;
% end
%
% nodeNum = nodeNum + 1;
% end
end