Main Content

nodepar

    Description

    nodepar is a tree-management utility.

    f = nodepar(t,n) returns a vector that contains the indices of the "parent(s)" of the nodes n in the tree t. In the tree, nodes are numbered from left to right and from top to bottom. The root index is 0.

    Note

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

    example

    f = nodepar(t,n,"deppos") returns a matrix that contains the depths and positions of the "parent(s)" of the nodes n in the tree t.

    Note

    nodepar(t,0,"deppos") or nodepar(t,[0,0],"deppos") returns [-1,0].

    Examples

    collapse all

    A tree of order 2 is a binary tree. Create a binary tree of depth 3. Recompose two of the nodes. Plot the tree.

    t = ntree(2,3);
    t = nodejoin(t,5);
    t = nodejoin(t,4);
    plot(t)

    Change the Node Label from Depth_Position to Index to get this figure:

    Obtain the depths and positions of the parents of the (2,2) and (3,1) nodes.

    nodepar(t,[2 2; 3 1],"deppos")
    ans = 2×2
    
         1     1
         2     0
    
    

    Obtain the indices of the parents of the nodes whose indices are 1, 7, and 14.

    nodepar(t,[1;7;14])
    ans = 3×1
    
         0
         3
         6
    
    

    Input Arguments

    collapse all

    Tree, specified as an ntree, dtree, or wptree object.

    Tree nodes, specified as a column vector that contains indices of the nodes or a matrix that contains the depths and positions of the nodes. If specified as a matrix, n(i,1) and n(i,2) are the depth and position, respectively, of the ith node.

    Data Types: double

    Output Arguments

    collapse all

    Tree nodes, returned as a column vector or matrix. If f is a vector, f contains node indices. If f is matrix, f(i,1) and f(i,2) are the depth and position, respectively, of the ith node.

    Version History

    Introduced before R2006a