MATLAB: Arrange cell matrix and get the sum

cell matrixsum

Hi,
"out" cell matrix has 1×365 cells. I have few questions about dealing with cells.
1) I need to delete cells from 361 to 365 in the "out" cell matrix. How can I do that in MATLAB?
2) After deleting, I need to get the sum like this. For example, from cell 1 – 8.
cell1 cell2 .....cell8 sum
0.0 0.1 0.0 0.1
0.0 0.2 0.5 0.7
0.0 0.1 0.1 0.2
.
.
For example,
for ii=1:8:360
sumout=sum(out{1,ii}{1,3});
end
But, this does not give the sum for all rows. Can someone help me?
Thanks in advance.

Best Answer

Putting lots of scalar values in a cell array is a waste of MATLAB's operation vectorizing abilities and this is why you are finding this task so difficult. I will use a simple numeric array, as this makes the doing these kind of operations much easier. Putting things in cell arrays is what you do when you have to, not for some trivial scalar values like this.
>> A = rand(365,1);
>> B = reshape(A(1:360),[],8);
>> sum(B,2)
ans =
4.4687
3.694
4.5899
3.4787
...
3.5861
3.7248
3.8888
5.2515
This code takes the first 360 values in the numeric array, arrange them into a matrix where each row has eight values. It then sums each row to give the final values in a 45x1 vector. And see how much easier it is to work with numeric arrays rather than cell arrays! You can convert the cell array to a numeric array using cell2mat(X), where X is the cell array.