t = uitree(fig,'checkbox');
parent = uitreenode(t,'Text','Sample Data');
child = uitreenode(parent,'Text','Sample 1');
child2 = uitreenode(parent,'Text','Sample 2');
grandchild = uitreenode(child2,'Text','Subsample 1');
grandchild2 = uitreenode(child2,'Text','Subsample 2');
nodes = [parent child child2 grandchild grandchild2];
nodes_name = {parent.Text, child.Text child2.Text grandchild.Text grandchild2.Text};
loadCheckboxStatus(t, nodes_name, nodes);
saveButton = uibutton(fig, 'Text', 'Save', 'Position', [10 10 100 30]);
saveButton.ButtonPushedFcn = @(src, event) saveCheckboxStatus(t);
loadButton = uibutton(fig, 'Text', 'Load', 'Position', [120 10 100 30]);
loadButton.ButtonPushedFcn = @(src, event) loadCheckboxStatus(t, nodes_name, nodes);
function saveCheckboxStatus(tree)
checkboxStatus = tree.CheckedNodes;
save('checkbox_status.mat', 'checkboxStatus');
function loadCheckboxStatus(tree, nodes_name, nodes)
if exist('checkbox_status.mat', 'file') == 2
loadedData = load('checkbox_status.mat');
for i = 1:numel(loadedData.checkboxStatus)
temp = loadedData.checkboxStatus(i).Text;
if ismember({temp}, nodes_name)
[~, index] = ismember({temp}, nodes_name);
checkedNodes = [checkedNodes, nodes(index)];
tree.CheckedNodes = checkedNodes;