matlab help urgent

Thread Starter

Judas543

Joined Jan 26, 2010
60
is there a easier way to find the sum of the cell?

y =

[1x3 double] [1x100 double] [8x6 double]

myCell = cell(1,3)
myCell{1,1} =[1,4,-10;]
myCell{1,2} =[9,5,3,8,9,2,1,0,8,9,3,5,0,7,2,5,1,0,5,9,6,5,1,1,0,2,2,9,4,9,1,7,3,2,0,3,2,7,6,5,5,2,6,9,2,6,8,3,4,6,4,5,6,1,8,4,5,2,5,8,7,3,8,6,1,6,0,3,4,6,7,9,4,6,4,1,8,4,3,5,0,5,9,8,5,3,2,0,0,2,7,3,4,8,1,9,0,2,6,5;]
myCell{1,3} = [25,21,35,29,99,69;1,56,62,54,3,94;92,4,45,83,2,91;61,3,9,65,58,100;59,90,21,28,26,63;82,80,66,18,98,65;65,62,31,44,80,56;44,86,83,24,65,96;]


cellfun(@(x) sum(x( : ),myCell) % Sum of total in each cell
sumy = sum(cellfun(@(x) sum(x( : ),myCell)) % All Total overall




That's what I have done before, I just put the cell contents into new array, which is a long long process if there are a lot of numbers in each cell?


Is there a much easier way to compute the sum of all the numbers in each cell array/
 

Thread Starter

Judas543

Joined Jan 26, 2010
60
find the sum of everything in the cell,

what I did was look inside each cell, for instance 1x3 had [1 4 -10]
and created a new array which contained those numbers. Is there an easier way without doing what I did

would it have to be a for loop
 

mik3

Joined Feb 4, 2008
4,843
find the sum of everything in the cell,

what I did was look inside each cell, for instance 1x3 had [1 4 -10]
and created a new array which contained those numbers. Is there an easier way without doing what I did

would it have to be a for loop
if the array is:

array[3]=[1 4 -10]

then:

for (i=0;i>2;i++)
{
sum=sum+array;
}
 
Top