Determine terminal nodes
N = tnodes(
T
)
N = tnodes(T
,'deppos')
[N,K] = tnodes(T
)
[N,K]
= tnodes(T
,'deppos'), M = N(K)
tnodes
is a tree-management
utility.
N = tnodes(
returns
the indices of terminal nodes of the tree T
)T
. N
is
a column vector.
The nodes are numbered from left to right and from top to bottom. The root index is 0.
N = tnodes(
returns
a matrix T
,'deppos')N
, which contains the depths and positions
of terminal nodes.
N(i,1)
is the depth of the i
-th
terminal node. N(i,2)
is the position of the i
-th
terminal node.
For [N,K] = tnodes(
or T
)[N,K]
= tnodes(
are
the indices reordered as in tree T
,'deppos'), M = N(K)T
, from
left to right.
% Create initial tree. ord = 2; t = ntree(ord,3); % Binary tree of depth 3. t = nodejoin(t,5); t = nodejoin(t,4); plot(t)
% Change Node Label from Depth_Position to Index
% (see the plot
function).
% List terminal nodes (index). tnodes(t) ans = 4 5 7 8 13 14 % List terminal nodes (Depth_Position). tnodes(t,'deppos') ans = 2 1 2 2 3 0 3 1 3 6 3 7