In app designer how do I load a previously saved array of checked-node objects that are children in the Tree?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
For debugging purporses I created a simple app in App Designer with a save button, a load button and a check-box tree. Component properties below:
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
LoadButton matlab.ui.control.Button
SaveButton matlab.ui.control.Button
Tree matlab.ui.container.CheckBoxTree
Node1 matlab.ui.container.TreeNode
Under11 matlab.ui.container.TreeNode
Under12 matlab.ui.container.TreeNode
Under13 matlab.ui.container.TreeNode
Node2 matlab.ui.container.TreeNode
Under21 matlab.ui.container.TreeNode
Under22 matlab.ui.container.TreeNode
Under23 matlab.ui.container.TreeNode
end
After selecting desired checked boxes in the tree (see image), the user can save the checked-nodes with the save button and the tree's check-boxes are then cleansed.
Save button function:
% Button pushed function: SaveButton
function SaveButtonPushed(app, event)
checked = app.Tree.CheckedNodes;
save('data.mat', 'checked')
app.Tree.CheckedNodes = [];
end
I want the user to be able to load that saved data and the tree's check-boxes be filled accordlingly after pressing the load button.
Load button function:
% Button pushed function: LoadButton
function LoadButtonPushed(app, event)
mfile = load('data.mat');
app.Tree.CheckedNodes = mfile.checked;
end
I receive the following error:
'CheckedNodes' must be an empty array or an array of TreeNode objects that are children in the Tree.
As a control, I loaded the mat file in the command window and it does indeed contain an array of tree node objects that correctly correspond to children in the tree:
>> mfile = load('data.mat')
mfile =
struct with fields:
checked: [3×1 TreeNode]
>> mfile.checked
ans =
3×1 TreeNode array:
TreeNode (Under12)
TreeNode (Under22)
TreeNode (Under23)
How do I fix this error?
/Rina
0 comentarios
Respuestas (1)
Swaraj
el 26 de Jun. de 2023
Hi Rina,
I understand that your are not able to assign tree nodes from .mat file into "CheckedNodes".
You cannot directly assign the tree nodes into “app.tree.CheckedNodes”.
You can make use of “Tag” field inside each tree node to solve this issue.
On clicking on save button: Instead of storing the entire tree node, you can store the tag in the .mat file.
On clicking on load button: Load the .mat file and use the tag with the help of “findobj” function to get the exact handle of the tree node and then mark it as checked.
Documentation of “findobj”: Find handle objects - MATLAB (mathworks.com)
Documentation for treenode: Control tree node appearance and behavior - MATLAB (mathworks.com)
Hope it helps!!!
Ver también
Categorías
Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!