Since you are only interested in the number of elements, here is a simplified version of flatten.m that @Ansari related to:
function n = my_numel(A) n = 0; for i=1:numel(A) if iscell(A{i}) n = n + my_numel(A{i}); else n = n + numel(A{i}); end end end
Result:
>> C = {{{1,2},{3,4,5}},{{{6},{7},{8}},{9}},10}; >> my_numel(C) ans = 10
EDIT:
If you feel lazy, we can let CELLPLOT do the counting:
hFig = figure('Visible','off'); num = numel( findobj(cellplot(C),'type','text') ); close(hFig)
In principle, we create an invisible figure, build an array of cells, count the number of βtextβ objects, and then delete the invisible figure.
Here is the plot below:
source share