我有一个具有以下结构的matlab结构
Tree:
feature : numerical value (= 1)
tru: numerical value (= 2)
gain: numerical value (= 3)
left: struct with left node
right: struct with right node
如何以树的形式打印出来?例如我想为根节点打印:
node 1 feature 1, tru 2, gain 3
节点 2 和 3 分别包含来自left
和right
结构的数据,其结构与根节点相同。
我想使用与上面描述的节点 1 相同的格式递归地打印整个树。
我可以通过打印我的节点 1
tree.feature
tree.tru
tree.gain
我不知道如何为所有节点递归地打印它的子节点。