MATLAB: Best practice of for loops and vectorisation, also maybe cumprod.

best practicecumprodfor loopMATLABstylevectoizationvectorisation

Hello all,
Like many, I am entering Matlab from a C (embedded) background, so am struggling with the adjustment to vectors.
Simple cases such as the following are beginning to be understandable to me.
for i = 1:length(myVector)
dim(i)= i;
end
is equivalent to
dim = 1:length(myVector);
However I'm stuck on a slightly more complex case relating to nested arrays. I have a nested cell array (someArray) and I wish to know the cumulative product of all those elements.
someArray = {cell(1,4); cell(1,13); cell(1,3); cell(1,2); cell(1,5)}
someArray =
{1x4 cell}
{1x13 cell}
{1x3 cell}
{1x2 cell}
{1x5 cell}
The following works, but it feels clunky.
product = 1;
for i = 1:length(someArray)
dim(i) = length(someArray{i});
product = product*dim(i);
end
count =
1560
I feel like this is hacky and that there's a better way, but my thinking is stuck. Is there a way to use cumprod()? Any suggestions are welcome. I'm using ML ed. R2012b

Best Answer

prod(cellfun(@length, someArray))