This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


(App Designer) Collapse tree node

Use only for App Designer apps, or when creating apps with the uifigure function.





collapse(parent) collapses the nodes of the parent tree or tree node. If parent is a Tree object, then the top-level of nodes in the tree display in a collapsed state. Any children beyond the top level do not collapse. If parent is a TreeNode object, then the specified node displays in a collapsed state, but the children inside that node do not collapse.

collapse(parent,'all') collapses all child nodes of the parent tree or tree node.


collapse all

Create a tree that has three levels of nodes, and expand all of the nodes.

f = uifigure;
tree = uitree(f,'Position',[20 20 175 100]);
% First level nodes
category1 = uitreenode(tree,'Text','Runners');
category2 = uitreenode(tree,'Text','Cyclists');

% Second level nodes
equip1 = uitreenode(category1,'Text','Equipment');
equip2 = uitreenode(category2,'Text','Equipment');
% Third level nodes
shoes = uitreenode(equip1,'Text','Running Shoes');
bike = uitreenode(equip2,'Text','Bicycle');
helmet = uitreenode(equip2,'Text','Helmet');

% Expand all nodes

Collapse the top-level of nodes.


Expand the Cyclists node.


The Equipment child node is already expanded because the previous collapse command collapsed only the Cyclists node. If you want to collapse all the child nodes, specify the 'all' option when you call the collapse function.

Input Arguments

collapse all

Parent tree or node, specified as a Tree object or TreeNode object.

Introduced in R2017b