Identify the portion of the uitree in CheckedNodes
조회 수: 10 (최근 30일)
이전 댓글 표시
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
채택된 답변
Everett Weber
2023년 1월 19일
편집: Everett Weber
2023년 1월 24일
댓글 수: 6
Sanket
2023년 1월 23일
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.
추가 답변 (1개)
Rohan
2023년 1월 19일
편집: Rohan
2023년 1월 19일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Data Preparation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!