Tree Structure For a Cell Array

2 vues (au cours des 30 derniers jours)
Muhammad Bhatti
Muhammad Bhatti le 27 Déc 2020
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

Réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by