I have a nested cell which represents a tree-structure:
CellArray={1,1,1,{1,1,1,{1,1,{1,{1 1 1 1 1 1 1 1}, 1,1},1,1},1,1,1},1,1,1,{1,1,1,1}};
Here's a simpler approach using a single while loop and repeated concatenation of the sub-cells:
temp = CellArray;
nNodes = 0;
while iscell(temp)
index = cellfun(@iscell, temp);
nNodes = nNodes + sum(index);
temp = [temp{index}];
end
And the result for the sample CellArray
in the question:
nNodes =
5