Identify the portion of the uitree in CheckedNodes
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Everett Weber
le 18 Jan 2023
Modifié(e) : Everett Weber
le 24 Jan 2023
When creating a tree with multiple treenodes, how can one identify the specific node that a checked item comes from?
Given the tree generated from the sample code in matlab (see below), How can I know the parent node for each checked node? Specifically, "train" could be under either vehicle or action in the example. tr.CHeckedNodes appears to return an array without indicating the parent node.
Thanks for the help.
fig = uifigure;
gl = uigridlayout(fig,[1 2]);
gl.ColumnWidth = {'2x','1x'};
vehicle=["train" "train" "plane" "plane" "plane"]';
action=["test" "test" "test" "train" "train"]';
T=table(vehicle, action);
tbl = uitable(gl,"Data",T);
tr = uitree(gl,'checkbox');
vars = string(T.Properties.VariableNames);
for k1 = 1:length(vars)
var = vars{k1};
varnode = uitreenode(tr,"Text",var);
rows = T{:,var};
names = categories(categorical(rows));
for k2 = 1:length(names)
text = names{k2};
uitreenode(varnode,"Text",text);
end
end
% manually check vehicle.train and action.test in tree
>> tr.CheckedNodes
ans =
2×1 TreeNode array:
TreeNode (train)
TreeNode (test)
5 commentaires
Réponse acceptée
Everett Weber
le 19 Jan 2023
Modifié(e) : Everett Weber
le 24 Jan 2023
6 commentaires
Sanket
le 23 Jan 2023
Hi Everett, thanks for the description of “filter_criteria”.
Since the second dimension determines the number of fields, I believe the following line:
num_vars=size(filter_criteria,1);
Should be replaced with:
num_vars=size(filter_criteria,2);
You can definitely attach an example that uses the functions, if it is not too much to add.
Plus de réponses (1)
Rohan
le 19 Jan 2023
Modifié(e) : Rohan
le 19 Jan 2023
The parent information is inherently present in each checked node. Since "tr.CheckedNodes" returns an array of checked nodes, the parent information can be found by accessing the "Parent" property of each node in this array, as shown below:
>> parent = tr.CheckedNodes(2).Parent
parent =
TreeNode (action) with properties:
Text: 'action'
Icon: ''
NodeData: []
Show all properties
Even if "train" is checked under both "vehicle" and "action", the parent of both "train" nodes can be found using the same syntax:
>> tr.CheckedNodes
ans =
2×1 TreeNode array:
TreeNode (train)
TreeNode (train)
>> tr.CheckedNodes(1).Parent
ans =
TreeNode (vehicle) with properties:
Text: 'vehicle'
Icon: ''
NodeData: []
Show all properties
>> tr.CheckedNodes(2).Parent
ans =
TreeNode (action) with properties:
Text: 'action'
Icon: ''
NodeData: []
Show all properties
0 commentaires
Voir également
Catégories
En savoir plus sur Text Data Preparation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
