MATLAB: Adding up sizes of cell arrays

cellcell arrayfor loopindexindexingloopMATLABmatrixsize;

Hi, I am wondering how to add up the sizes of cell arrays for each "class." The "classes" are part of a loop. I need to be able to index each sum into j.
for j = 1:NumberOfClasses
sizeOfCellArray{j} = size(CellArray{j})
sum(j) = sizeOfCellArray(j).*sizeOfCellArray(j+1)
end
I know that this is wrong, because sizeOfCellArray(j+1) gets an error (Index exceeds matrix dimensions), but am I on the right track?

Best Answer

You've made sizeofCellArray a cell, but then treat it like a double:
for j = 1:NumberOfClasses
sizeOfCellArray(j,:) = size(CellArray{j})
sum(j,:) = sizeOfCellArray(j,:).*sizeOfCellArray(j+1,:)
end
I'm not sure how you're accessing j+1 though? I would also advise that you change the name of the 'sum' variable, in case you want to use the built-in sum function later