Main Content

ntree

NTREE constructor

    Description

    example

    T = ntree(ord,d) returns an NTREE object, which is a complete tree of order ord and depth d.

    • T = ntree is equivalent to T = ntree(2,0).

    • T = ntree(ord) is equivalent to T = ntree(ord,0).

    T = ntree(ord,d,s) sets a "split scheme" for nodes.

    T = ntree(ord,d,s,u) sets the user data field of T.

    You can also specify function inputs this way: T = ntree('order',ord,'depth',d,'spsch',s,'ud',u). For unspecified inputs, the defaults are ord = 2 and d = 0 , s = ones(ord,1]) , u = {}.

    [T,nb] = ntree(___) also returns the number of terminal nodes (leaves) of T.

    Examples

    collapse all

    Create a binary tree (a tree of order 2) of depth 3.

    t2 = ntree(2,3);

    Use the plot tree GUI plot to plot the tree.

    plot(t2)

    Create a quadtree (a tree of order 4) of depth 2. Split all except the third node.

    t4 = ntree(4,2,[1 1 0 1]);
    plot(t4)

    Input Arguments

    collapse all

    Tree order, specified as a positive integer.

    Data Types: double

    Tree depth, specified as a nonnegative integer.

    Data Types: double

    Split scheme, specified as an ord-by-1 logical array. The root of the tree can be split and it has ord children. You can split the jth child if s(j) = 1. Each node that you can split has the same property as the root node.

    Example: T = ntree(2,3,[1 0]) splits the first node at every level.

    User data to set in the ud field of T, specified as an array, cell array, or structure array.

    Example: t = ntree(2,3,[0 1],{1,"aa",rand(3,3)})

    Output Arguments

    collapse all

    Tree, returned as a NTREE object.

    The NTREE object has these fields:

    wtbo

    Parent object

    order

    Tree order

    depth

    Tree depth

    spsch

    Split scheme for nodes

    tn

    Column vector with terminal node indices

    The wtbo parent object has these fields:

    wtboInfo

    Object information

    ud

    User data field

    For more information on object fields, type:

    help ntree/get
    

    Number of terminal nodes (leaves) of T.

    Data Types: double

    Version History

    Introduced before R2006a

    See Also