フィルターのクリア

Tree Structure For a Cell Array

1 回表示 (過去 30 日間)
Muhammad Bhatti
Muhammad Bhatti 2020 年 12 月 27 日
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 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by