I want to have the sum of all matrices stored in a cell array. Currently I do this
StackSummImage = zeros(size(imageList{1}));
for k = 1:stackSize
StackSummImage = StackSummImage + imageList{k};
end
But I would rather want to write it in a single line if possible.
If each of the N images is K x K, you can use
catto concatenate all the images into a K x K x N array, and then sum it along the third dimension:Edit: You mentioned in the comments that you can’t create a single array, because of memory limits. Below is the memory usage profile when I first allocate a 1500x1500x1500 array of doubles (which takes around 30 GB) and deallocate it, followed by allocating a cell array of 1500 arrays, each of which is a 1500×1500 double array. As you can see, the total memory usage is the same in both cases.