noleaves
Purpose
Determine nonterminal nodes
Syntax
Description
N = noleaves(T) returns the indices of nonterminal nodes of the tree T (i.e., nodes that are not leaves). N is a column vector.
The nodes are ordered from left to right as in tree T.
N = noleaves(T,'dp') returns a matrix N, which contains the depths and positions of nonterminal nodes.
N(i,1) is the depth of the i-th nonterminal node and
N(i,2) is the position of the i-th nonterminal node.
Examples
% 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 nonterminal nodes (index).
ntnodes_ind = noleaves(t)
ntnodes_ind =
0
1
2
3
6
% List nonterminal nodes (Depth_Position).
ntnodes_depo = noleaves(t,'dp')
ntnodes_depo =
0 0
1 0
1 1
2 0
2 3
See Also
leaves
| | Provide feedback about this page |
 | nodesplt | | ntnode |  |
Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
Get the Interactive Kit