Main Content

istnode

Terminal nodes indices test

    Description

    istnode is a tree-management utility.

    r = istnode(t,n) returns the ranks (in left to right terminal nodes ordering) for the terminal nodes n that exist in the tree t and 0 otherwise.

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

    example

    Examples

    collapse all

    Create a binary tree of depth 3.

    ord = 2;
    t = ntree(ord,3);

    Merge the nodes with indices 4 and 5. Plot the tree.

    t = nodejoin(t,5);
    t = nodejoin(t,4);
    plot(t)

    Figure contains an axes object and an object of type uimenu. The axes object with title Tree Decomposition contains 21 objects of type line, text.

    Return the ranks of the terminal nodes with depth-position equal to (1,0), (3,1), and (4,5) that exist in the tree, and 0 otherwise.

    n = [1 0;3 1;4 5];
    istnode(t,n)
    ans = 3×1
    
         0
         2
         0
    
    

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

    Find the terminal nodes and return the ranks for the terminal nodes in the tree.

    istnode(t,14)
    ans = 
    6
    
    istnode(t,15)
    ans = 
    0
    
    istnode(t,[1;7;10;14;25])
    ans = 5×1
    
         0
         1
         0
         6
         0
    
    

    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

    Terminal node test results, returned as a vector of nonnegative integers. If n(i,:) is a terminal node in the tree t, then r(i) is the rank of the node. Otherwise, r(i) equals 0.

    Version History

    Introduced before R2006a

    See Also

    |