Identify the portion of the uitree in CheckedNodes
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Everett Weber
il 18 Gen 2023
Modificato: Everett Weber
il 24 Gen 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 Commenti
Risposta accettata
Everett Weber
il 19 Gen 2023
Modificato: Everett Weber
il 24 Gen 2023
6 Commenti
Sanket
il 23 Gen 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.
Più risposte (1)
Rohan
il 19 Gen 2023
Modificato: Rohan
il 19 Gen 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 Commenti
Vedere anche
Categorie
Scopri di più su Text Data Preparation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!