Reputation: 30127
Suppose I have a 3x4 matrix
Now how to calculate a matrix of the same size, which contains each element being a sum of itself and all elements, which are higher and lefter than it?
Upvotes: 2
Views: 49
Reputation: 114866
You must be looking for cumsum
:
integ = cumsum( cumsum( A, 1 ), 2 );
For example:
A = [1 2 3;
4 5 6];
cumsum( cumsum( A, 1 ), 2 )
Results with:
1 3 6
5 12 21
PS,
This operation is sometimes refereed to as integral image.
Upvotes: 7