Tree Structure For a Cell Array
1 view (last 30 days)
Show older comments
Hi,
I am trying to generate a code which creates a tree of a cell array. I have a 6x4 cell array. I want the first column to be the parent nodes and subsequent columns to be child nodes of the previous column. I was able to find a code but it makes my entire cell array a parent node. I have been trying to modify it but am having troubles. Below is the code, any help will be much appreciated! Thanks!
function [treearray, nodevals] = getTreeArray(cellarray)
[nodes, ~, nodevals] = treebuilder(cellarray, 1);
treearray = [0, nodes];
function [out, node, nodevals] = treebuilder(cellarray, rnode)
out = []; nodevals = {};
% Start node off at root node
node = rnode;
[rows, columns] = size(cellarray);
for jj = 1:columns
for ii = 1:rows
node = node + 1;
if iscell(cellarray{ii})
[tb, node, nv] = treebuilder(cellarray{ii}, node);
out = [out, rnode, tb];
nodevals = [nodevals, nv];
else
out = [out, rnode];
nodevals = [nodevals, {node; cellarray{ii}}];
end
end
end
end
end
0 Comments
Answers (0)
See Also
Categories
Find more on HDF5 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!