Hi,
I try to sum over the third dimension of a matrix A, say A = ceil(5*rand(4,4,3)).
The third dimension equals variation in time. For t= 0 I want to have A(:,:,1); for t= 1 I want to have A(:,:,1) + A(:,:,2); for t=3 I want to have A(:,:,1) + A(:,:,2) + A(:,:,3).
The code below works, however, I want to do it without for-loops. Can someone help me?
[nr, nc, nd]= size(A)for i=1:ndfor ii= 1:nrfor jj=1:ncB(ii,jj,i) = sum(reshape(A(ii,jj,[1:i]),i,1)));endendend
Best Answer