MATLAB: Mean of cells in loop with different dimensions

cell arraysmean of cell

I have a loop, and creat B{i,1} on it. now I need to calculate the mean of each cell.i used meanOfCities(i)= mean(cell2mat(B(i,1))) ; it workes just for 4 loop, and then this error : Index exceeds matrix dimensions. will occure.

Best Answer

Inside the loop, right after you assigned B{i, 1} take the mean and assign that to a vector:
cellContents = B{i, 1}; % A vector, matrix, or higher dimensional array - whatever it is...
theMeans(i) = mean(cellContents(:));
Now, after your loop, theMeans will be the mean of every cell that you've assigned.