MATLAB: How to count the number of rows in a cell array’s cells

cell arrayefficiencyheightMATLAB and Simulink Student Suitememorynumelpreallocationspeed

My goal is to create a table as a subset of a cell array's contents. I understand that it's better to preallocate memory size and then truncate empty rows rather than have an array grow with each loop repetition. So I wish to count the total number of rows in each cell as the maximum possible size of the resulting table.
This does not work:
>> size(newvoldata)
ans =
1 200
Nor does this:
>> numel(newvoldata)
ans =
200
For example, one cell can have a table such that
>> height(newvoldata{160})
ans =
439
Is there a MATLAB command that more quickly does the following?
counter = 0;
for loop = 1:length(newvoldata)
counter = counter + size(newvoldata{loop},1);
end
counter
I suspect there is some command similar to numel that does this for cell arrays. Is there one? Or should I use an implicit function ?

Best Answer

For a cell array of tables:
sum(cellfun(@height,newvoldata))
For a cell array of numeric/char/cell/struct arrays:
sum(cellfun('size',newvoldata,1))