Tree Structure For a Cell Array
조회 수: 1 (최근 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!