nodepar

Node parent

Syntax

F = nodepar(T,N)
F = nodepar(T,N,'deppos')

Description

nodepar is a tree-management utility.

F = nodepar(T,N) returns the indices of the Äúparent(s)Äù of the nodes N in the tree T where N can be a column vector containing the indices of nodes or a matrix that contains the depths and positions of nodes. In the last case, N(i,1) is the depth of the i-th node and N(i,2) is the position of the i-th node.

F = nodepar(T,N,'deppos') is a matrix that contains the depths and positions of returned nodes. F(i,1) is the depth of the i-th node and F(i,2) is the position of the i-th node.

nodepar(T,0) or nodepar(T,[0,0]) returns -1.

nodepar(T,0,'deppos') or nodepar(T,[0,0],'deppos') returns [-1,0].

The nodes are numbered from left to right and from top to bottom. The root index is 0.

Examples

% Create binary tree of depth 3. 
t = ntree(2,3); 
t = nodejoin(t,5); 
t = nodejoin(t,4); 
plot(t)

% Change Node Label from Depth_Position to Index
% (see the plot function).

% Nodes parent.
nodepar(t,[2 2],'deppos')

ans =
    1     1

nodepar(t,[1;7;14])

ans =
    0
    3
    6
Introduced before R2006a