Tree Structure For a Cell Array
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!